Cua Sandbox offers three lifecycle patterns. Ephemeral sandboxes are automatically destroyed when theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/trycua/cua/llms.txt
Use this file to discover all available pages before exploring further.
async with block exits — ideal for CI, tests, and one-off tasks where state has no value after the job. Persistent sandboxes outlive the creating process and can be reconnected to by name, which is useful for long-running development environments or multi-step workflows split across separate scripts. Connect mode attaches to an already-running sandbox without starting or stopping it.
Ephemeral sandboxes
UseSandbox.ephemeral() as an async context manager. The sandbox is destroyed automatically when the block exits, whether the block completes normally or raises an exception.
Ephemeral with cloud resources
Persistent sandboxes
UseSandbox.create() when the sandbox must outlive the script. Call await sb.disconnect() to drop the connection while leaving the sandbox running, then reconnect later by name.
disconnect vs destroy vs delete
These three operations are distinct. Choosing the wrong one can silently discard work or leave a sandbox consuming resources.| Method | Effect | Use when |
|---|---|---|
await sb.disconnect() | Drops the network connection; sandbox keeps running | You will reconnect later |
await sb.destroy() | Disconnects and permanently deletes the sandbox | You are finished with this sandbox |
await Sandbox.delete(name) | Permanently deletes by name, no connection needed | You want to clean up from a different process |
Reconnecting to a running sandbox
Sandbox.connect() supports both await and async with. The context manager calls disconnect() on exit — the sandbox is not destroyed.
Sandbox.connect never starts or stops the sandbox. It only manages the control connection. If the sandbox has exited, connect will raise an error.Listing running sandboxes
UseSandbox.list() to enumerate all running and suspended sandboxes. Filter by local=True to list only sandboxes on the local runtime.
SandboxInfo fields include name, status, os_type, host, vnc_url, api_url, and created_at.
Suspending and resuming
Suspend a sandbox to save its state to disk without destroying it. Resume picks up from the saved state.On local QEMU runtimes, suspend uses a QMP snapshot. On Docker it uses
docker pause. On Lume it performs a stop. Cloud suspend calls the cua.ai API.Choosing a local runtime
Passlocal=True to any lifecycle method to run on your own machine. Cua automatically selects the correct runtime backend for the image type.