Sandbox
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()
Parameters
nameStringReturns
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
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()
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()
created, starting, running, draining, paused, stopped, or crashed. Returns a refreshed metadata handle. 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
statusStringReturns
sandbox.restart()
force: true to kill, timeout: in seconds to change how long shutdown can take, or detached: true for a local background start.
On microsandbox cloud, graceful restart is supported, but timeout expiry cannot escalate to force kill. force: true is local-only, and detached: affects only local process ownership.
Parameters
forceBooleantimeoutNumeric | nildetachedBooleanReturns
sandbox.destroy()
Parameters
forceBooleantimeoutNumeric | nilReturns
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()
h.deny_response(true) to enable readable 403 responses. Optionally set deny_message to customize the body; {host} names the blocked hostname. Setting a message alone does not enable responses. Enabling requires a supporting local runtime; cloud rejects it. See HTTP denial responses for which requests receive a response.
Example
Example
SandboxHandle
handle.name
Returns
handle.status
Returns
handle.config_json
Returns
handle.active_config_json
Returns
handle.last_failure_message
Returns
handle.kill()
Parameters
timeoutNumericReturns
handle.wait_until_stopped()
Returns
handle.ping()
Returns
handle.touch()
Returns
handle.metrics()
Returns
handle.refresh()
Returns
handle.connect()
Returns
handle.start()
Parameters
detachedBooleanReturns
handle.remove()
Returns
handle.id
Returns
handle.stop()
stop has no built-in timeout. Both bounded forms raise Microsandbox::Error on expiry without force-killing; zero expires before sending a request. A stale identity is refused rather than stopping a replacement. On cloud, a timeout limits the SDK wait; an accepted stop may continue server-side.
Parameters
timeoutNumericReturns
handle.stop_with_timeout()
Parameters
secondsNumericReturns
handle.connect_or_start()
starting, or start it when it is created, stopped, or crashed. draining and paused are rejected. detached: true affects only a required local start; connecting to an already-running sandbox does not change ownership.
Parameters
detachedBooleanReturns
handle.wait_for_status()
status, returning a refreshed handle. The method does not have a built-in timeout.
Parameters
statusStringReturns
handle.restart()
Sandbox#restart.
Parameters
forceBooleantimeoutNumeric | nildetachedBooleanReturns
handle.destroy()
Parameters
forceBooleantimeoutNumeric | nilReturns
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
nameStringstatusStringexit_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()
SandboxHandle.
sandbox.list_jobs()
SandboxHandle.
Job
job.id
job.inspect
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.