Sandbox
Live inspection
info returns a hash with string keys id, name, status, last_failure_message, created_at and updated_at. The status value is a symbol. Optional timestamps are RFC3339 strings or nil. name and id require no backend I/O. List pages contain unprepared Sandbox objects without per-item connections or startup.
Each inspection method performs a fresh backend lookup without starting the resource. A failed lookup raises or returns an error; it never substitutes cached data. Use info when several related fields are needed together. Configuration is the latest persisted settings, which may differ from settings applied to the current run. Retain the returned value when you want a snapshot.
Class methods
Microsandbox::Sandbox.create()
Example
Example
Parameters
nameStringimageStringcpusIntegermax_cpusIntegermemoryIntegermax_memoryIntegerenvHashlabelsHashworkdirStringshellStringhostnameStringuserStringdetachedBooleanephemeralBooleanmax_durationIntegeridle_timeoutIntegerreplaceBooleanreplace_timeoutNumericroot_diskIntegerdisable_networkBooleannetworkSymbol | HashproxyOutboundProxysecretsArray<Hash>quiet_logsBooleanentrypointArray<String>initStringpull_policyStringscriptsHashslugStringReturns
Microsandbox::Sandbox.builder()
Parameters
nameStringReturns
Microsandbox::Sandbox.start()
Parameters
nameStringdetachedBooleanReturns
Microsandbox::Sandbox.get_running()
Example
Example
Microsandbox::Sandbox.get()
Example
Example
sb.ensure_running()
Example
Example
Microsandbox::Sandbox.recover_storage()
Parameters
selectionsHash<String, String>accept_selected_viewBooleanfalse. Required for explicit selections, which may omit writes from other disk branches.legacy_writers_stoppedBooleanfalse. On macOS, confirm that legacy VMs across all homes are stopped and new writers are prevented during recovery.Returns
StorageRecoveryname (string) identifies the sandbox. ready (boolean) confirms protected storage is ready, and originals_retained (boolean) confirms the original disks were retained.Microsandbox::Sandbox.list()
Example
Example
Parameters
cursorStringlimitIntegerlabelsHashReturns
Microsandbox::Sandbox.remove()
Parameters
nameStringReturns
Microsandbox::Sandbox.with()
Example
Example
Parameters
nameStringoptionsHashReturns
Microsandbox::Sandbox.connect_or_create()
Example
Example
Sandbox.create when name conflicts must remain an error, or explicit replace options when the old identity should be discarded.
Parameters
nameStringoptionsHashReturns
Instance methods
sandbox.name
Returns
sandbox.owns_lifecycle?
Returns
sandbox.backend
Returns
sandbox.status
Returns
created, starting, running, draining, paused, stopped, or crashed.sandbox.last_failure_message
Returns
sandbox.kill()
Parameters
timeoutNumericReturns
sandbox.wait_until_stopped()
Returns
sandbox.ping()
Returns
sandbox.touch()
Returns
sandbox.metrics()
Returns
sandbox.request_kill()
Returns
sandbox.detach()
owns_lifecycle? reflects the change, and guest operations and explicit stop/destroy remain available. Failure raises without losing the object or clearing its cleanup authority.
Returns
sandbox.stop()
timeout: bounds the wait without changing graceful shutdown into forced termination. These semantics require the matching updated native extension and runtime.
Parameters
timeoutNumericReturns
sandbox.stop_with_timeout()
Microsandbox::Error without force-killing; zero expires before sending a request. Call kill separately when forced termination is intended.
Parameters
secondsNumericReturns
sandbox.request_stop()
wait_until_stopped to observe completion.
Returns
sandbox.id
Returns
sandbox.wait_for_status()
info for a fresh observation afterward. The observed status may change after this wait completes.
Wait without a built-in timeout until this exact sandbox reaches the requested lifecycle status. Ruby’s Timeout.timeout does not reliably interrupt the native wait. Use an SDK operation with an explicit timeout when you need a bounded shutdown.
Parameters
statusSymbol | StringReturns
sandbox.restart()
force: true to kill, timeout: in seconds to change how long shutdown can take, or detached: true for a local background start.
Parameters
forceBooleantimeoutNumeric | nildetachedBooleanReturns
sandbox.destroy()
Parameters
forceBooleantimeoutNumeric | nilReturns
config
kind, name, spec, unavailable and redacted. kind distinguishes local specifications from remote inspection projections. Remote mount sources and secret material are deliberately absent; the metadata identifies those paths without inventing defaults. The hash is not creation input. See inspection result shapes.
SandboxBuilder
builder.image()
Parameters
valueStringReturns
builder.cpus()
Parameters
valueIntegerReturns
builder.max_cpus()
Parameters
valueIntegerReturns
builder.memory()
Parameters
valueIntegerReturns
builder.max_memory()
Parameters
valueIntegerReturns
builder.env()
Parameters
keyStringvalueStringReturns
builder.workdir()
Parameters
valueStringReturns
builder.shell()
Parameters
valueStringReturns
builder.hostname()
Parameters
valueStringReturns
builder.user()
Parameters
valueStringReturns
builder.intercept_tls()
Sandbox.create also accepts intercept_tls: true.
builder.detached()
Parameters
valueBooleanReturns
builder.ephemeral()
Parameters
valueBooleanReturns
builder.max_duration()
Parameters
valueIntegerReturns
builder.idle_timeout()
Parameters
valueIntegerReturns
builder.replace()
Returns
builder.root_disk()
Parameters
valueIntegerReturns
builder.disable_network()
Returns
builder.proxy()
Parameters
valueOutboundProxyReturns
builder.quiet_logs()
Returns
builder.entrypoint()
Parameters
valueArray<String>Returns
builder.init()
Parameters
valueStringReturns
builder.label()
Parameters
keyStringvalueStringReturns
builder.replace_with_timeout()
Parameters
secondsNumericReturns
builder.create()
Example
Example
Returns
image!, which mutate the builder and return nil. See VSock for vsock and vsock_dgram. Network allowlists, secret entries, pull policy, scripts, and slug are creation keywords, not Ruby builder methods.
builder.connect_or_create()
Microsandbox::Sandbox.connect_or_create. This consumes the builder.
Returns
builder.http()
403 errors. Call h.deny_response(false) to disable them. network_deny_message and secret_deny_message customize the respective messages. Requires a supporting local runtime. See HTTP denial responses.
Example
Example
SandboxMetrics
metrics.to_h()
Example
Example
Returns
Fields
cpu_percentFloatvcpu_time_nsIntegermemory_bytesIntegermemory_limit_bytesIntegerdisk_read_bytesIntegerdisk_write_bytesIntegernet_rx_bytesIntegernet_tx_bytesIntegeruptime_msIntegertimestampStringStop result
Fields
nameStringstatusSymbolexit_codeInteger | nilsignalInteger | nilobserved_atStringsourceString | nilIdentity errors
Stale handles raiseMicrosandbox::SandboxReplacedError rather than acting on a replacement with the same name. See Error handling.
Example
Example
Installation requirements
Example
Example
Managed jobs
Run and reconnect to background commands. See Background jobs for lifecycle, retention, and runtime limits.sandbox.exec_detached()
exec options: cwd, user, env, timeout, stdin, tty, and rlimits. Stdin defaults to :pipe; :null closes it, and a String supplies at most 64 KiB followed by EOF.
Example
Example
sandbox.get_job()
sandbox.list_jobs()
Job
job.id
job.info
job.wait
job.signal
job.kill
job.eof
job.logs
since is inclusive and until exclusive, both in Unix milliseconds; from_cursor cannot be combined with since.
job.log_stream
each for automatic cleanup or close the stream explicitly.
job.follow_logs
logs.
job.attach
JobAttachment
attachment.recv
each iterates events and detaches on exit. Input and output can run on separate Ruby threads.
attachment.write_stdin
attachment.resize
attachment.detach
close is an alias.
JobLogStream
stream.next
each iterates entries and closes the stream on exit.
stream.close
Nested virtualization
nested_virt: true | false controls nested virtualization for a local sandbox. Omit it to inherit configuration (off by default). See nested VM snapshots for requirements.
Sandbox.local / Sandbox.remote
Storage recovery
Microsandbox::Sandbox.recover_storage()
Parameters
selectionsHash<String, String>accept_selected_viewBooleanfalse. Required for explicit selections, which may omit writes from other disk branches.legacy_writers_stoppedBooleanfalse. On macOS, confirm that legacy VMs across all homes are stopped and new writers are prevented during recovery.Returns
StorageRecoveryname (string) identifies the sandbox. ready (boolean) confirms protected storage is ready, and originals_retained (boolean) confirms the original disks were retained.