Snapshots let you create a persistent point-in-time capture of a running sandbox, including both its filesystem and memory state.
You can then use a snapshot to spawn new sandboxes that start from the exact same state.The original sandbox continues running after the snapshot is created, and a single snapshot can be used to create many new sandboxes.
The sandbox is briefly paused during the snapshot process but automatically returns to running state. The sandbox ID stays the same after the snapshot completes.
During the snapshot, the sandbox is temporarily paused and resumed. This causes all active connections (e.g. WebSocket, PTY, command streams) to be dropped. Make sure your client handles reconnection properly.
The snapshot ID can be used directly with Sandbox.create() to spawn a new sandbox from the snapshot. The new sandbox starts with the exact filesystem and memory state captured in the snapshot.
Copy
Ask AI
import { Sandbox } from 'e2b'const snapshot = await sandbox.createSnapshot()// Create a new sandbox from the snapshotconst newSandbox = await Sandbox.create(snapshot.snapshotId)
import { Sandbox } from 'e2b'// Returns true if deleted, false if the snapshot was not foundconst deleted = await Sandbox.deleteSnapshot(snapshot.snapshotId)
Both snapshots and templates create reusable starting points for sandboxes, but they solve different problems.
Templates
Snapshots
Defined by
Declarative code (Template builder)
Capturing a running sandbox
Reproducibility
Same definition produces the same sandbox every time
Captures whatever state exists at that moment
Best for
Repeatable base environments
Checkpointing, rollback, forking runtime state
Use templates when every sandbox should start from an identical, known state — pre-installed tools, fixed configurations, consistent environments.
Use snapshots when you need to capture or fork live runtime state that depends on what happened during execution.
Checkpointing agent work — an AI agent has loaded data and produced partial results in memory. Snapshot it so you can resume or fork from that point later.
Rollback points — snapshot before a risky or expensive operation (running untrusted code, applying a migration, refactoring a web app). If it fails, rollback - spawn a fresh sandbox from the snapshot before the operation happened.
Forking workflows — spawn multiple sandboxes from the same snapshot to explore different approaches in parallel.
Cached sandboxes — avoid repeating expensive setup by snapshotting a sandbox that has already loaded a large dataset or started a long-running process.
Sharing state — one user or agent configures an environment interactively, snapshots it, and others start from that exact state.