Sandbox is the synchronous entry point for all sandbox operations. Every instance exposes a .commands sub-module for running commands and a .files sub-module for filesystem operations.
Class methods
Sandbox.create()
Create a new sandbox and return a connected Sandbox instance.
Template ID or alias to boot. Defaults to
'base' (Ubuntu 22.04).Sandbox lifetime in seconds. The sandbox is killed automatically when the
timeout expires unless
lifecycle.on_timeout is set to 'pause'.Arbitrary key-value pairs attached to the sandbox. Searchable via
Sandbox.list().Environment variables injected into the sandbox at boot time.
Whether to enable the MITM security proxy. Set to
False only for trusted
workloads where TLS interception overhead is unacceptable.When
False, all outbound traffic is blocked by adding deny_out: ["0.0.0.0/0"] to the network config. Use network for fine-grained
control.Fine-grained network configuration. Overrides
allow_internet_access when
provided. See SandboxNetworkOpts.Full security policy including PII detection, injection defense,
transformations, audit, and env masking. See
SecurityPolicy.
Resource constraints passed directly to the orchestrator (e.g.
{"cpu": 2, "memory_mb": 2048}).Controls sandbox behaviour on timeout. See
SandboxLifecycle.
API key override for this call.
Domain override for this call. Supports
host:port format.Per-request HTTP timeout in seconds.
Sandbox
Sandbox.connect()
Connect to an existing sandbox by ID without creating a new one.
The ID of the sandbox to connect to.
Optionally update the sandbox timeout on connection.
API key override.
Domain override.
Per-request HTTP timeout in seconds.
Sandbox
Sandbox.list()
List sandboxes with optional filtering and pagination.
Filter by metadata or state. See SandboxQuery.
Maximum number of results to return.
Pagination cursor from a previous
list() call.API key override.
Domain override.
Per-request HTTP timeout in seconds.
dict — raw JSON containing sandboxes list and optional next_token.
Instance methods
sbx.kill()
Kill and destroy the sandbox. After this call the sandbox ID becomes invalid.
Per-request HTTP timeout in seconds.
bool — True if the sandbox was killed, False if it was already dead.
sbx.is_running()
Check whether the sandbox is currently in the running state.
Per-request HTTP timeout in seconds.
bool
sbx.set_timeout()
Update the sandbox timeout. The new timeout is relative to the current time.
New timeout in seconds.
Per-request HTTP timeout in seconds.
None
sbx.get_info()
Fetch the current metadata and state of the sandbox.
Per-request HTTP timeout in seconds.
SandboxInfo
sbx.get_metrics()
Retrieve CPU, memory, and disk usage metrics for a time range.
Start of the time range. Defaults to beginning of sandbox lifetime.
End of the time range. Defaults to now.
Per-request HTTP timeout in seconds.
list[SandboxMetrics]
sbx.pause()
Pause a running sandbox, preserving its in-memory state for later resumption.
Per-request HTTP timeout in seconds.
None
sbx.resume()
Resume a previously paused sandbox.
Per-request HTTP timeout in seconds.
None
sbx.create_snapshot()
Create a snapshot of the sandbox. The snapshot can be used as a template ID
to boot new sandboxes from a known state.
Per-request HTTP timeout in seconds.
SnapshotInfo
sbx.snapshot()
Create a manual snapshot of this sandbox. Manual snapshots accumulate — every
call creates a new persistent checkpoint that survives sbx.kill(). Use
Sandbox.restore() or sbx.list_snapshots()
to retrieve and fork from them.
Per-request HTTP timeout in seconds.
Snapshot
sbx.list_snapshots()
List all snapshots (periodic, pause, and manual) for this sandbox, newest first.
Per-request HTTP timeout in seconds.
list[Snapshot]
Sandbox.restore()
Restore a sandbox from a snapshot. The restored sandbox may run on a different
worker than the original. Returns a usable Sandbox instance already connected
to the restored sandbox.
The sandbox to restore.
Specific snapshot to restore from. If omitted, the most recent snapshot is
used (preference order: pause > periodic > manual).
API key override.
Domain override.
Per-request HTTP timeout in seconds.
Sandbox
sbx.close()
Close the underlying HTTP client and release connection pool resources. Does
not kill the sandbox. Call this when you are done with the object but want the
sandbox to keep running.
Context manager
Sandbox supports the context manager protocol. __exit__ closes the HTTP client but does not kill the sandbox. Call sbx.kill() explicitly inside the block if you want the sandbox destroyed.
Properties
| Property | Type | Description |
|---|---|---|
sbx.sandbox_id | str | Unique sandbox identifier. |
sbx.commands | Commands | Commands sub-module. |
sbx.files | Filesystem | Filesystem sub-module. |
sbx.pty | Pty | PTY sub-module. |