Skip to main content
The Python SDK ships an async-native variant of the sandbox API on top of asyncio. Every method on the sync 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.
If you only ever use one sandbox at a time and your code is otherwise synchronous, the sync 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, or await AsyncSandbox.connect(sandbox_id) to attach to an existing one. Every instance method is awaited:
Refer to the SDK Reference for the full method list — the names, parameters, and return types are identical to the sync API. The pages below walk through the same workflow with async syntax.

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. Use asyncio.gather to start and run sandboxes concurrently:
Each evaluate call creates, executes against, and terminates its own sandbox in parallel with the others.

Connect to an existing sandbox

Reattach to a named sandbox after resume, 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:
For long-running processes you want to stop yourself, send a signal directly — don’t 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 — pass name= at creation time. checkpoint works on any sandbox, including ephemeral ones.

Learn more

SDK Reference

Full method list — 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.