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.
str | None
default:"'base'"
Template ID or alias to boot. Defaults to
'base' (Ubuntu 22.04).int | None
default:"300"
Sandbox lifetime in seconds. The sandbox is killed automatically when the
timeout expires unless
lifecycle.on_timeout is set to 'pause'.dict[str, str] | None
default:"None"
Arbitrary key-value pairs attached to the sandbox. Searchable via
Sandbox.list().dict[str, str] | None
default:"None"
Environment variables injected into the sandbox at boot time.
bool
default:"True"
Whether to enable the edge proxy security proxy. Set to
False only for trusted
workloads where TLS interception overhead is unacceptable.bool
default:"True"
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.dict | SandboxNetworkOpts | None
default:"None"
Fine-grained network configuration. Overrides
allow_internet_access when
provided. See SandboxNetworkOpts.SecurityPolicy | None
default:"None"
Full security policy including PII detection, injection defense,
transformations, audit, and env masking. See
SecurityPolicy.
SandboxLifecycle | None
default:"None"
Controls sandbox behaviour on timeout. See
SandboxLifecycle.
str | None
default:"$DECLAW_API_KEY"
API key override for this call.
str | None
default:"$DECLAW_DOMAIN"
Domain override for this call. Supports
host:port format.float | None
default:"None"
Per-request HTTP timeout in seconds.
Sandbox
Sandbox.connect()
Connect to an existing sandbox by ID without creating a new one.
str
required
The ID of the sandbox to connect to.
int | None
default:"None"
Optionally update the sandbox timeout on connection.
str | None
default:"$DECLAW_API_KEY"
API key override.
str | None
default:"$DECLAW_DOMAIN"
Domain override.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Sandbox
Sandbox.list()
List sandboxes with optional filtering and pagination.
SandboxQuery | None
default:"None"
Filter by metadata or state. See SandboxQuery.
int | None
default:"None"
Maximum number of results to return.
str | None
default:"None"
Pagination cursor from a previous
list() call.str | None
default:"$DECLAW_API_KEY"
API key override.
str | None
default:"$DECLAW_DOMAIN"
Domain override.
float | None
default:"None"
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.
float | None
default:"None"
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.
float | None
default:"None"
Per-request HTTP timeout in seconds.
bool
sbx.set_timeout()
Update the sandbox timeout. The new timeout is relative to the current time.
int
required
New timeout in seconds.
float | None
default:"None"
Per-request HTTP timeout in seconds.
None
sbx.get_info()
Fetch the current metadata and state of the sandbox.
float | None
default:"None"
Per-request HTTP timeout in seconds.
SandboxInfo
sbx.get_metrics()
Retrieve CPU, memory, and disk usage metrics for a time range.
datetime.datetime | None
default:"None"
Start of the time range. Defaults to beginning of sandbox lifetime.
datetime.datetime | None
default:"None"
End of the time range. Defaults to now.
float | None
default:"None"
Per-request HTTP timeout in seconds.
list[SandboxMetrics]
sbx.pause()
Pause a running sandbox, preserving its in-memory state for later resumption.
float | None
default:"None"
Per-request HTTP timeout in seconds.
None
sbx.resume()
Resume a previously paused sandbox.
float | None
default:"None"
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.
float | None
default:"None"
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.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Snapshot
sbx.list_snapshots()
List all snapshots (periodic, pause, and manual) for this sandbox, newest first.
float | None
default:"None"
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.
str
required
The sandbox to restore.
str | None
default:"None"
Specific snapshot to restore from. If omitted, the most recent snapshot is
used (preference order: pause > periodic > manual).
str | None
default:"$DECLAW_API_KEY"
API key override.
str | None
default:"$DECLAW_DOMAIN"
Domain override.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Sandbox
sbx.get_host()
Return the URL that reverse-proxies HTTP traffic to the given port inside the sandbox. Requires allow_public_traffic to be enabled in the sandbox’s network config (the default).
int
required
The port number to proxy to inside the sandbox.
str — fully qualified HTTPS URL for the port proxy endpoint.
sbx.get_mcp_url()
Return the URL for an MCP server listening on port 50005 inside the sandbox. Equivalent to sbx.get_host(50005) + "/mcp".
str
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.