Typical flow
Static methods
Sandbox.create()
Example
Example
SandboxConfig for the full set. Pulls the image if needed, boots the VM, starts the guest agent, and waits until it is ready to accept commands. Sandbox names must be non-empty and no longer than 128 UTF-8 bytes.
The returned Sandbox is an async context manager. Use async with to guarantee cleanup; on exit the sandbox is killed and its persisted state removed.
Parameters
namestr**kwargsSandboxConfigimage, cpus, memory, volumes, ports, network, secrets, detached, and more.Returns
Sandbox.create_with_progress()
Example
Example
create() but returns a PullSession that lets you track image pull progress before the sandbox is ready. This method is synchronous (not awaitable); the async work happens through the PullSession.
Parameters
namestr**kwargsSandboxConfigReturns
Sandbox.start()
Example
Example
Parameters
namestrdetachedboolTrue, the sandbox survives after your process exits. Default False.Returns
Sandbox.get()
Example
Example
Parameters
namestrReturns
Sandbox.list()
Example
Example
Returns
Sandbox.list_with()
Example
Example
Parameters
cursorstr | Nonenext_cursor from the preceding page.limitint | NonelabelsMapping[str, str] | NoneNone returns every sandbox, like list().Returns
Sandbox.remove()
Example
Example
Parameters
namestrInstance properties
sb.name
Example
Example
await sb.name().
Returns
sb.owns_lifecycle
create() or start() owns lifecycle, including when created with detached=True, until you call detach(). Handles upgraded via SandboxHandle.connect() do not own lifecycle. This is an async property; use await sb.owns_lifecycle.
Returns
True if this handle owns the lifecycle.sb.fs
Example
Example
sb.fs (no await). See Filesystem for API details.
Returns
Instance methods
Command execution (exec, exec_stream, shell, shell_stream) is documented on the Execution page; SSH (ssh) on the SSH page. The lifecycle, attach, metrics, and logs methods follow.
sb.attach()
Example
Example
Parameters
cmdstrargslist[str] | Nonecwdstr | Noneuserstr | NoneenvMapping[str, str] | Nonedetach_keysstr | NoneReturns
sb.attach_shell()
Example
Example
Returns
sb.ping()
Example
Example
core.ping and waits for core.pong; it does not start stopped sandboxes and raises an error if the sandbox is not running or agentd cannot respond. After upgrading from a runtime that predates protocol generation 6, restart already-running sandboxes so the guest agent understands the message.
Returns
sb.touch()
Example
Example
core.touch, receives core.touched, and advances the guest activity sequence used by the runtime idle-timeout monitor. It does not start stopped sandboxes and it does not bypass max_duration.
Returns
sb.modify()
Example
Example
"live", "next start", "requires restart", or "unsupported", and apply is all-or-nothing.
cpus and memory resize live within the max_cpus / max_memory ceilings; raising a ceiling requires a restart. Env and workdir changes affect future execs only. On a stopped sandbox, changes are saved for the next boot.
Secret changes are Rust-SDK and CLI only for now. The CLI equivalent is msb modify.
The returned plan dict mirrors the canonical JSON shape:
resize_status reports when the sandbox has finished adjusting.
Parameters
cpusint | Nonemax_cpus.max_cpusint | Nonememoryint | Nonemax_memory.max_memoryint | NoneenvMapping[str, str] | Noneenv_rmlist[str] | NonelabelsMapping[str, str] | Nonelabels_rmlist[str] | Noneworkdirstr | Nonepolicystr | None”no_restart” (default) applies only changes that can complete without restarting; “next_start” persists changes for the next start without mutating a running VM; “restart” restarts if needed so restart-required changes become active now.dry_runboolTrue, compute the plan without applying anything. Default False.Returns
dry_run=True.sb.metrics()
Example
Example
Returns
sb.metrics_stream()
Example
Example
MetricsStream supports both recv() and async for.
Parameters
intervalfloat1.0.Returns
sb.logs()
Example
Example
exec.log. Backed by an on-disk JSON Lines file the runtime writes via the relay tap. Works on running and stopped sandboxes alike; there is no protocol traffic. The same method is available on SandboxHandle for callers that don’t want to start the sandbox first.
The default sources are "stdout", "stderr", and "output" (PTY-merged). Pass "system" to also include synthetic lifecycle markers and runtime/kernel diagnostic lines, or "all" as shorthand for all four. Timestamps are exposed as float ms since the Unix epoch (UTC) for parity with SandboxMetrics.timestamp_ms.
Parameters
tailint | Nonesince_msfloat | Noneuntil_msfloat | Nonesourceslist[LogReadSource] | NoneNone = [“stdout”, “stderr”, “output”]. Add “system” to merge runtime/kernel diagnostics, or use “all” for all four.Returns
sb.log_stream()
Example
Example
LogStream. With follow=True the stream stays open and yields new entries as they are written, like tail -f. Resume an earlier stream by passing the cursor of the last entry you saw as from_cursor. Also available on SandboxHandle.
Parameters
sourceslist[LogReadSource] | Nonesince_msfloat | Nonefrom_cursorstr | Noneuntil_msfloat | NonefollowboolTrue, keep the stream open and yield new entries as they arrive. Default False.Returns
sb.stop()
Example
Example
timeout to override the graceful shutdown window before force-kill escalation.
Parameters
timeoutfloat | NoneNone uses the ten-second default.sb.request_stop()
Example
Example
wait_until_stopped() when the caller needs to observe the terminal state.
sb.kill()
Example
Example
fsync’d may be lost, same durability semantics as a sudden power loss on a physical machine. Prefer stop() for graceful shutdown that gives the workload a chance to flush.
Parameters
timeoutfloat | Nonesb.request_kill()
Example
Example
sb.request_drain()
Example
Example
exec calls are rejected; the sandbox transitions to stopped when all in-flight commands finish. Useful for zero-downtime rotation of worker sandboxes. Use wait_until_stopped() when the caller needs stopped-state observation.
sb.wait_until_stopped()
Example
Example
Returns
sb.detach()
Example
Example
Sandbox.get().
Patch
Factory class for rootfs patches passed toSandbox.create(..., patches=[...]). Each static method returns a PatchConfig. By default a patch that targets a path already present in the image errors at boot; pass replace=True on the operation to allow overwriting. mkdir and remove are idempotent. See Patches for conceptual context.
Patch.text()
Example
Example
path.
Parameters
pathstrcontentstrmodeint | None0o644.replaceboolTrue, overwrite an existing path.Patch.append()
content to an existing file at path. If the file lives in a lower image layer, it’s copied up first.
Parameters
pathstrcontentstrPatch.mkdir()
path. Idempotent: a no-op if the directory already exists.
Parameters
pathstrmodeint | None0o755.Patch.remove()
path. Idempotent: a no-op if the path doesn’t exist.
Parameters
pathstrPatch.copy_file()
src into the guest rootfs at dst.
Parameters
srcstrdststrmodeint | None0o644. None keeps the source mode.replaceboolTrue, overwrite an existing path at dst.Patch.copy_dir()
src into the guest rootfs at dst.
Parameters
srcstrdststrreplaceboolTrue, overwrite an existing path at dst.Patch.symlink()
link pointing to target.
Parameters
targetstrlinkstrreplaceboolTrue, overwrite an existing path at link.Types
SandboxConfig
Used by create() · create_with_progress()
The keyword arguments accepted bycreate() and create_with_progress(). There is no SandboxConfig object you construct directly; these are passed as **kwargs.
InitConfig
Used by create(init=…)
Custom init specification. Pass it (or one of the equivalent shorthand shapes) as theinit= kwarg to create() to hand PID 1 inside the guest off to your own init binary after agentd’s setup. Frozen dataclass. See Custom init system for image picks, shutdown semantics, and tradeoffs.
init= kwarg follows the same shape as other structured create kwargs: a bare scalar for the simple case, or a dataclass / dict for the rich case.
SecurityProfile
Used by create(security=…)
Sandbox-wide in-guest security profile. AStrEnum, so the string values are accepted directly.
SandboxPage
One stable, newest-first page returned bySandbox.list() or Sandbox.list_with().
SandboxHandle
Returned by Sandbox.get() · Sandbox.list() · Sandbox.list_with()
A lightweight handle to an existing sandbox (running or stopped). Provides status, configuration, and lifecycle control without an active connection to the guest agent. You cannotexec or fs on a handle; call .start() or .connect() to upgrade to a full Sandbox.
SandboxPingResult
Returned by ping()
Agent reachability result.SandboxTouchResult
Returned by touch()
Explicit idle-refresh result.SandboxStopResult
Returned by wait_until_stopped()
Observed terminal sandbox state returned bywait_until_stopped().
SandboxStatus
Used by SandboxHandle.status · SandboxStopResult.status
The string status values a sandbox can report. AStrEnum, exposed as plain strings on status fields.
SandboxMetrics
Returned by metrics() · metrics_stream()
Point-in-time resource usage snapshot.MetricsStream
Returned by metrics_stream()
Async stream for receiving periodic metrics snapshots.LogEntry
Returned by logs() · iterated from LogStream
A single captured log entry returned bylogs() or iterated from a LogStream.
LogStream
Returned by log_stream()
Async stream ofLogEntry values, returned by log_stream().
LogSource
Used by LogEntry.source · logs(sources=…)
The string values thesource field on a LogEntry can take, also accepted by logs(sources=[...]) and log_stream(sources=[...]). The read form additionally accepts "all".
LogLevel
Used by create(log_level=…)
Sandbox process log verbosity. AStrEnum, so the string values are accepted directly.
PullPolicy
Used by create(pull_policy=…)
Controls when the SDK fetches an OCI image from the registry. AStrEnum, so the string values are accepted directly.
RegistryAuth
Used by create(registry_auth=…)
Credentials for authenticating to a private container registry. Frozen dataclass; construct directly or viaRegistryAuth.basic(username, password).
PatchConfig
Returned by Patch.* factory methods · used by create(patches=…)
A single rootfs patch. Produced by thePatch factory; you’d normally not construct one directly. Frozen dataclass.
PullSession
Returned by create_with_progress()
Returned bycreate_with_progress(). The factory itself is synchronous; use the returned session as an async context manager to track image pull progress.
PullEvent
Iterated from PullSession.progress
Native event object emitted byPullSession.progress. Inspect event_type and the fields relevant to that event; fields that do not apply to a particular event are None.