Sandbox handle has a one-to-one async counterpart on AsyncSandbox: same names, same parameters, just async def and awaited.
When to use it
Reach for the async API when:- You’re driving multiple sandboxes concurrently (e.g. fanning out work with
asyncio.gather). - Your application is already asyncio-based (FastAPI, aiohttp, an LLM agent loop, etc.) and you don’t want to mix in blocking calls.
- You’re streaming output from many processes at once.
Sandbox API is simpler and equivalent.
The shape of the API
AsyncSandbox is the runtime handle for a single sandbox. Use await AsyncSandbox.create(...) to provision and connect, await AsyncSandbox.connect(sandbox_id) to attach to an existing one, or await AsyncSandbox.get_or_create(name, ...) to reuse a named sandbox and create it on first use. Every instance method is awaited:
Create and run
AsyncSandbox is also an async context manager. Use async with to terminate the sandbox automatically when the block exits:
Run many sandboxes in parallel
The async API is designed for fan-out. Useasyncio.gather to start and run sandboxes concurrently:
evaluate call creates, executes against, and terminates its own sandbox in parallel with the others.
Get or create a named sandbox
UseAsyncSandbox.get_or_create() when concurrent tasks may request the same named sandbox. The method creates the sandbox on first use, connects to it on later calls, resolves concurrent create conflicts, and resumes it when suspended.
resume=False to return an existing suspended sandbox without resuming it; call await sandbox.resume() before running commands against that handle. See Get or create in the SDK Reference for the complete behavior and limitations.
Connect to an existing sandbox
Reattach to a named sandbox afterresume, or operate on a sandbox another process created:
Unlike the sync
Sandbox.sandbox_id property, which transparently fetches
sandbox info on first access, the async AsyncSandbox.sandbox_id cannot
block on a network call. Call await sandbox.info() (or any other awaited
method that resolves the sandbox, like status()) once before reading
sandbox.sandbox_id on a freshly connected handle.Background processes and streaming output
Start a process, keep the handle, and collect its output once it finishes:follow_output first, since it would block waiting for the process to exit:
File operations
Suspend, resume, and snapshot
Suspend and resume require a named sandbox, so passname= at creation time. checkpoint works on any sandbox, including ephemeral ones.
Learn more
SDK Reference
Full method list that applies to both sync and async APIs.
Lifecycle
State machine, suspend/resume, timeouts.
Commands & Processes
Run commands, capture output, and manage background processes.
Snapshots
Capture and restore full VM state.