Create without waiting
Passwait=False and the create returns as soon as the sandbox is durable, with the sandbox in the pending state. The sandbox is scheduled and started exactly as a normal create; only the waiting moves to you.
- CLI
- Python
- TypeScript
- HTTP
ready() polls the sandbox every two seconds until it is running and returns a connected Sandbox. status() fetches the current state once. A sandbox known only by id, in another process for example, is picked up with Sandbox.connect(sandbox_id), which also waits while the sandbox is pending.
Why a sandbox is pending
While a sandbox waits, itspending_reason says why. Read it from status(), from GET /sandboxes/{id}, or from a SandboxPending error.
Limit the queue time
By default a pending sandbox waits until there is room, however long that takes. If you would rather give up at some point, setmax_pending_secs on the create. When the bound runs out while the sandbox is still waiting for capacity, the server terminates it with termination_reason: no_capacity, and the last pending_reason explains what it was waiting for. 0 fails at once if the sandbox cannot be placed right away.
- CLI
- Python
- TypeScript
- HTTP
suspended rather than terminating, so nothing it holds is lost.
Timeouts
The blockingSandbox.create() and pending.ready(timeout=...) raise SandboxPending when their wait runs out. The sandbox is not deleted. It keeps its place in the queue and starts when there is room. The error carries sandbox_id and the last pending_reason, so you can wait again, connect from elsewhere, or terminate it.
- Python
- TypeScript
cancel_on_timeout=True (cancelOnTimeout: true). Deleting a pending sandbox yourself terminates it with termination_reason: cancelled.
Before SDK versions with
wait, a create that timed out deleted its sandbox. A retry loop written for that behaviour (“create failed, create again”) now accumulates pending sandboxes until they run or are cancelled. Reuse the id from the error instead, or set cancel_on_timeout.Retries
A create withwait=False answers in well under a second, so a lost response is rare, but a retry of an unanswered create can still make a second sandbox. When that matters, give the sandbox a name. Names are unique per namespace: a repeated create of the same name is an HTTP 409, and get_or_create resolves it to the existing sandbox. Named sandboxes suspend rather than terminate when their timeout_secs elapses, so terminate them explicitly when the work is done.
Create many sandboxes at once
For a batch, create everything up front withwait=False, then poll the list endpoint. One list call sees every sandbox in the namespace, so ten thousand sandboxes cost one request per poll, not ten thousand.
- Python
- TypeScript
no_capacity and drop out of the list. Webhook subscribers can replace the poll with the sandbox.running and sandbox.failed events.
Learn more
- Sandbox Lifecycle for the full state machine.
- SDK Reference for every
create()parameter. - Create Sandbox for the HTTP contract.