Create point-in-time snapshots of sandboxes and restore them to resume from a saved state.
A snapshot captures the complete state of a running sandbox — memory contents, filesystem, and process state — and saves it to persistent storage. Snapshots can be restored to create new sandboxes that resume exactly where the original left off.
Pass a snapshot_id to Sandbox.create() to start a new sandbox that resumes from that state.
Python
TypeScript
# Create a fresh sandbox from the snapshotsbx = Sandbox.create(snapshot_id="snap-abc123")# The sandbox is already set up — libraries installed, files presentresult = sbx.commands.run("python3 -c 'import pandas; print(pandas.__version__)'")print(result.stdout) # 2.1.0result = sbx.commands.run("ls /workspace/")print(result.stdout) # data.csv
When create_snapshot() is called, the sandbox briefly pauses to capture a consistent memory image and then resumes automatically. The sandbox continues running after the snapshot completes.The snapshotting pause is typically under one second for sandboxes with 256 MB of RAM.
Install heavy ML libraries once, snapshot the result, then create new sandboxes from that snapshot for every request. Eliminates the pip install torch overhead from every run.
# One-time setupsetup_sbx = Sandbox.create()setup_sbx.commands.run("pip3 install torch transformers sentence-transformers")snap = setup_sbx.create_snapshot()setup_sbx.kill()# Fast warm-start for every agent runagent_sbx = Sandbox.create(snapshot_id=snap.snapshot_id)# torch is already installed
Checkpoint long-running tasks
Snapshot a sandbox mid-computation so you can restore it if the run fails.
sbx = Sandbox.create()sbx.commands.run("python3 download_dataset.py")# Checkpoint after expensive downloadcheckpoint = sbx.create_snapshot()sbx.commands.run("python3 train_model.py") # may fail# If it fails, restore from checkpoint and retry
Branch sandbox state
Create multiple independent sandboxes from the same snapshot to explore different execution paths.
snap = base_sbx.create_snapshot()# Explore two different approaches in parallelbranch_a = Sandbox.create(snapshot_id=snap.snapshot_id)branch_b = Sandbox.create(snapshot_id=snap.snapshot_id)branch_a.commands.run("python3 approach_a.py")branch_b.commands.run("python3 approach_b.py")
Snapshots capture the state of a single sandbox at a point in time. They do not capture external state such as in-flight network connections, database transactions, or changes to services outside the sandbox.