E2B sandboxes are persistent environments. When you pause a sandbox, its full state — filesystem and memory, including all running processes and loaded variables — is preserved indefinitely. Resume it at any time and pick up exactly where you left off. Snapshots let you capture that state and spawn multiple new sandboxes from it.Documentation Index
Fetch the complete documentation index at: https://e2b-squash-sandbox-pages.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Sandbox state transitions
Understanding how sandboxes transition between states:State descriptions
- Running: The sandbox is actively running and can execute code. This is the initial state after creation.
- Paused: The sandbox execution is suspended but its state is preserved.
- Snapshotting: The sandbox is briefly paused while a persistent snapshot is being created. It automatically returns to Running. See Snapshots.
- Killed: The sandbox is terminated and all resources are released. This is a terminal state.
Changing sandbox state
Pause and resume
Pausing a sandbox
When you pause a sandbox, both the sandbox’s filesystem and memory state will be saved. This includes all the files in the sandbox’s filesystem and all the running processes, loaded variables, data, etc.Resuming a sandbox
When you resume a sandbox, it will be in the same state it was in when you paused it. This means that all the files in the sandbox’s filesystem will be restored and all the running processes, loaded variables, data, etc. will be restored.Listing paused sandboxes
You can list all paused sandboxes by calling theSandbox.list method and supplying the state query parameter.
Removing paused sandboxes
You can remove paused sandboxes by calling thekill method on the Sandbox instance.
Timeout on connect
When you connect to a sandbox, the inactivity timeout resets. The default is 5 minutes, but you can pass a custom timeout to theSandbox.connect() method:
Network behavior during pause
If you have a service (for example a server) running inside your sandbox and you pause the sandbox, the service won’t be accessible from the outside and all the clients will be disconnected. If you resume the sandbox, the service will be accessible again but you need to connect clients again.Limitations
Pause and resume performance
- Pausing a sandbox takes approximately 4 seconds per 1 GiB of RAM
- Resuming a sandbox takes approximately 1 second
Paused sandbox retention
- Paused sandboxes are kept indefinitely — there is no automatic deletion or time-to-live limit
- You can resume a paused sandbox at any time
Continuous runtime limits
- A sandbox can remain running (without being paused) for:
- 24 hours on the Pro tier
- 1 hour on the Base tier
- After a sandbox is paused and resumed, the continuous runtime limit is reset
Auto-pause and auto-resume
Auto-pause and auto-resume are configured together through thelifecycle object when creating a sandbox. Auto-pause suspends a sandbox when its timeout expires. Auto-resume wakes it back up when activity arrives.
Configure lifecycle on create
.kill(), the sandbox is permanently deleted and cannot be resumed.
Lifecycle options
onTimeout/on_timeoutkill(default): sandbox is terminated when timeout is reachedpause: sandbox is paused when timeout is reached
autoResume/auto_resumefalse(default): paused sandboxes do not auto-resumetrue: paused sandboxes auto-resume on activitytrueis valid only whenonTimeout/on_timeoutispause
Behavior summary
- Default behavior is equivalent to
onTimeout: "kill"withautoResume: false. onTimeout: "pause"withautoResume: falsegives auto-pause without auto-resume.onTimeout: "pause"withautoResume: truegives auto-pause with auto-resume.Sandbox.connect()can still be used to resume a paused sandbox manually.
autoResume: false, resume explicitly with Sandbox.connect().
Timeout after auto-resume
When a sandbox auto-resumes, it restarts with a 5-minute minimum timeout. If you originally created the sandbox with a longer timeout, that value carries over. The countdown begins from the moment the sandbox resumes, not from when it was first created. For example, if you create a sandbox with a 2-minute timeout:- The sandbox runs for 2 minutes, then pauses.
- Activity arrives and the sandbox auto-resumes.
- A 5-minute timeout starts (the 5-minute minimum applies because the original timeout was shorter).
- If no further activity resets the timeout, the sandbox pauses again after 5 minutes.
onTimeout: "pause" + autoResume: true) is persistent across pause/resume cycles.
You can change the timeout after the sandbox resumes by calling
setTimeout/set_timeout. See Change sandbox timeout during runtime.What counts as activity
Auto-resume is triggered by the sandbox activity - that’s both HTTP traffic and controlling the sandbox from the SDK. That includes SDK operations like:sandbox.commands.run(...)sandbox.files.read(...)sandbox.files.write(...)- opening a tunneled app URL or sending requests to a service running inside the sandbox
autoResume is enabled, the next supported operation resumes it automatically. You do not need to call Sandbox.connect() first.
SDK example: pause, then read a file
Use cases
Web and dev/preview servers
UseonTimeout: "pause" + autoResume: true so inbound traffic can wake a paused sandbox automatically.
This works for both basic web/API servers and dev or preview servers you open occasionally.
Agent/tool execution
For queued tasks or tool calls, create once and keep using the same sandbox handle. If it is paused, it will auto-resume when you run the next command.Per-user sandboxes
For multi-tenant apps, keep a map of sandbox IDs by user. On each request, connect to the user’s existing sandbox (which auto-resumes if paused) or create a new one.Cleanup
Auto-resume is persistent, meaning if your sandbox resumes and later times out again, it will pause again. Each time the sandbox resumes, it gets a fresh timeout (at least 5 minutes, or longer if the original creation timeout exceeds that) — so the sandbox keeps cycling between running and paused as long as activity arrives. If you call.kill(), the sandbox is permanently deleted and cannot be resumed.
Snapshots
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.Prerequisites
Snapshots require templates with envd versionv0.5.0 or above. If you are using a custom template created before envd v0.5.0, you need to rebuild it.
You can check the template envd version using the e2b template list command or by viewing the templates list on the dashboard.
Snapshots vs. Pause/Resume
| Pause/Resume | Snapshots | |
|---|---|---|
| Effect on original sandbox | Pauses (stops) the sandbox | Sandbox briefly pauses, then continues running |
| Relationship | One-to-one — resume restores the same sandbox | One-to-many — snapshot can spawn many new sandboxes |
| Use case | Suspend and resume a single sandbox | Create a reusable checkpoint |
Snapshot flow
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.Create a snapshot
You can create a snapshot from a running sandbox instance.Create a sandbox from a snapshot
The snapshot ID can be used directly withSandbox.create() to spawn a new sandbox from the snapshot. The new sandbox starts with the exact filesystem and memory state captured in the snapshot.
List snapshots
You can list all snapshots. The method returns a paginator for iterating through results.Filter by sandbox
You can filter snapshots created from a specific sandbox.Delete a snapshot
Snapshots vs. Templates
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 |
Snapshot use cases
- 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.