Skip to content

Commit 61c8978

Browse files
Merge branch 'main' into auto-resume-docs
2 parents 83a3491 + 25ebcf4 commit 61c8978

8 files changed

Lines changed: 219 additions & 13 deletions

File tree

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node 24.11.0

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"docs/sandbox/lifecycle-events-api",
100100
"docs/sandbox/lifecycle-events-webhooks",
101101
"docs/sandbox/persistence",
102+
"docs/sandbox/snapshots",
102103
"docs/sandbox/auto-resume",
103104
"docs/sandbox/git-integration",
104105
"docs/sandbox/metrics",

docs/sandbox/lifecycle-events-api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Monitor sandbox lifecycle events"
33
sidebarTitle: Lifecycle events API
44
---
55

6-
The lifecycle API provides RESTful endpoints to request the latest sandbox lifecycle events. This allows you to track when sandboxes are created, paused, resumed, updated, or killed, along with metadata.
6+
The lifecycle API provides RESTful endpoints to request the latest sandbox lifecycle events. This allows you to track when sandboxes are created, paused, resumed, updated, snapshotted, or killed, along with metadata.
77
All requests require authentication using your team [API key](/docs/api-key#where-to-find-api-key).
88

99
Query Parameters:

docs/sandbox/lifecycle-events-webhooks.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,5 @@ The following event types can be subscribed to via webhooks, they are used as th
346346
- `sandbox.lifecycle.updated` - Sandbox configuration updates
347347
- `sandbox.lifecycle.paused` - Sandbox pausing
348348
- `sandbox.lifecycle.resumed` - Sandbox resuming
349+
- `sandbox.lifecycle.checkpointed` - Sandbox [snapshot](/docs/sandbox/snapshots) created
349350

docs/sandbox/persistence.mdx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,28 @@ This includes not only state of the sandbox's filesystem but also the sandbox's
1717

1818
Understanding how sandboxes transition between different states is crucial for managing their lifecycle effectively. Here's a diagram showing the possible state transitions:
1919

20-
<Frame>
21-
<img src="/images/diagram.png" />
22-
</Frame>
20+
```mermaid actions={false}
21+
flowchart TD
22+
start(( )) -->|Sandbox.create| Running
23+
24+
Running["<b>Running</b><br/>• Active execution<br/>• Consumes resources"]
25+
Paused["<b>Paused</b><br/>• Preserves memory and files<br/>• Cannot execute code"]
26+
Snapshotting["<b>Snapshotting</b><br/>• Creates persistent snapshot<br/>• Briefly pauses execution"]
27+
Killed["<b>Killed</b><br/>• Resources released<br/>• Cannot be resumed"]
28+
29+
Running -->|pause| Paused
30+
Running -->|createSnapshot| Snapshotting
31+
Paused -->|connect| Running
32+
Snapshotting -->|snapshot complete| Running
33+
Running -->|kill| Killed
34+
Paused -->|kill| Killed
35+
```
2336

2437
### State descriptions
2538

2639
- **Running**: The sandbox is actively running and can execute code. This is the initial state after creation.
2740
- **Paused**: The sandbox execution is suspended but its state is preserved.
41+
- **Snapshotting**: The sandbox is briefly paused while a persistent snapshot is being created. It automatically returns to Running. See [Snapshots](/docs/sandbox/snapshots).
2842
- **Killed**: The sandbox is terminated and all resources are released. This is a terminal state.
2943

3044
### Changing sandbox's state
@@ -265,6 +279,10 @@ If you resume the sandbox, the service will be accessible again but you need to
265279
- Pausing a sandbox takes approximately **4 seconds per 1 GiB of RAM**
266280
- Resuming a sandbox takes approximately **1 second**
267281

282+
### Paused sandbox retention
283+
- Paused sandboxes are kept **indefinitely** — there is no automatic deletion or time-to-live limit
284+
- You can resume a paused sandbox at any time
285+
268286
### Continuous runtime limits
269287
- A sandbox can remain running (without being paused) for:
270288
- **24 hours** on the **Pro tier**

docs/sandbox/snapshots.mdx

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
---
2+
title: "Sandbox snapshots"
3+
sidebarTitle: Snapshots
4+
---
5+
6+
Snapshots let you create a persistent point-in-time capture of a running sandbox, including both its filesystem and memory state.
7+
You can then use a snapshot to spawn new sandboxes that start from the exact same state.
8+
9+
The original sandbox continues running after the snapshot is created, and a single snapshot can be used to create many new sandboxes.
10+
11+
## Snapshots vs. Pause/Resume
12+
13+
| | Pause/Resume | Snapshots |
14+
|---|---|---|
15+
| Effect on original sandbox | Pauses (stops) the sandbox | Sandbox briefly pauses, then continues running |
16+
| Relationship | One-to-one — resume restores the same sandbox | One-to-many — snapshot can spawn many new sandboxes |
17+
| Use case | Suspend and resume a single sandbox | Create a reusable checkpoint |
18+
19+
For pause/resume functionality, see [Persistence](/docs/sandbox/persistence).
20+
21+
## Snapshot flow
22+
23+
```mermaid actions={false}
24+
graph LR
25+
A[Running Sandbox] -->|createSnapshot| B[Snapshotting]
26+
B --> C[Snapshot Created]
27+
B --> A
28+
C -->|Sandbox.create| D[New Sandbox 1]
29+
C -->|Sandbox.create| E[New Sandbox 2]
30+
C -->|Sandbox.create| F[New Sandbox N]
31+
```
32+
33+
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.
34+
35+
<Warning>
36+
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.
37+
</Warning>
38+
39+
## Create a snapshot
40+
41+
You can create a snapshot from a running sandbox instance.
42+
43+
<CodeGroup>
44+
```js JavaScript & TypeScript
45+
import { Sandbox } from 'e2b'
46+
47+
const sandbox = await Sandbox.create()
48+
49+
// Create a snapshot from a running sandbox
50+
const snapshot = await sandbox.createSnapshot()
51+
console.log('Snapshot ID:', snapshot.snapshotId)
52+
```
53+
```python Python
54+
from e2b import Sandbox
55+
56+
sandbox = Sandbox.create()
57+
58+
# Create a snapshot from a running sandbox
59+
snapshot = sandbox.create_snapshot()
60+
print('Snapshot ID:', snapshot.snapshot_id)
61+
```
62+
</CodeGroup>
63+
64+
You can also create a snapshot by sandbox ID using the static method.
65+
66+
<CodeGroup>
67+
```js JavaScript & TypeScript
68+
import { Sandbox } from 'e2b'
69+
70+
// Create a snapshot by sandbox ID
71+
const snapshot = await Sandbox.createSnapshot(sandboxId)
72+
console.log('Snapshot ID:', snapshot.snapshotId)
73+
```
74+
```python Python
75+
from e2b import Sandbox
76+
77+
# Create a snapshot by sandbox ID
78+
snapshot = Sandbox.create_snapshot(sandbox_id)
79+
print('Snapshot ID:', snapshot.snapshot_id)
80+
```
81+
</CodeGroup>
82+
83+
## Create a sandbox from a snapshot
84+
85+
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.
86+
87+
<CodeGroup>
88+
```js JavaScript & TypeScript highlight={5}
89+
import { Sandbox } from 'e2b'
90+
91+
const snapshot = await sandbox.createSnapshot()
92+
93+
// Create a new sandbox from the snapshot
94+
const newSandbox = await Sandbox.create(snapshot.snapshotId)
95+
```
96+
```python Python highlight={5}
97+
from e2b import Sandbox
98+
99+
snapshot = sandbox.create_snapshot()
100+
101+
# Create a new sandbox from the snapshot
102+
new_sandbox = Sandbox.create(snapshot.snapshot_id)
103+
```
104+
</CodeGroup>
105+
106+
## List snapshots
107+
108+
You can list all snapshots. The method returns a paginator for iterating through results.
109+
110+
<CodeGroup>
111+
```js JavaScript & TypeScript
112+
import { Sandbox } from 'e2b'
113+
114+
const paginator = Sandbox.listSnapshots()
115+
116+
const snapshots = []
117+
while (paginator.hasNext) {
118+
const items = await paginator.nextItems()
119+
snapshots.push(...items)
120+
}
121+
```
122+
```python Python
123+
from e2b import Sandbox
124+
125+
paginator = Sandbox.list_snapshots()
126+
127+
snapshots = []
128+
while paginator.has_next:
129+
items = paginator.next_items()
130+
snapshots.extend(items)
131+
```
132+
</CodeGroup>
133+
134+
### Filter by sandbox
135+
136+
You can filter snapshots created from a specific sandbox.
137+
138+
<CodeGroup>
139+
```js JavaScript & TypeScript
140+
import { Sandbox } from 'e2b'
141+
142+
const paginator = Sandbox.listSnapshots({ sandboxId: 'your-sandbox-id' })
143+
const snapshots = await paginator.nextItems()
144+
```
145+
```python Python
146+
from e2b import Sandbox
147+
148+
paginator = Sandbox.list_snapshots(sandbox_id="your-sandbox-id")
149+
snapshots = paginator.next_items()
150+
```
151+
</CodeGroup>
152+
153+
## Delete a snapshot
154+
155+
<CodeGroup>
156+
```js JavaScript & TypeScript
157+
import { Sandbox } from 'e2b'
158+
159+
// Returns true if deleted, false if the snapshot was not found
160+
const deleted = await Sandbox.deleteSnapshot(snapshot.snapshotId)
161+
```
162+
```python Python
163+
from e2b import Sandbox
164+
165+
Sandbox.delete_snapshot(snapshot.snapshot_id)
166+
```
167+
</CodeGroup>
168+
169+
## Snapshots vs. Templates
170+
171+
Both snapshots and [templates](/docs/template/quickstart) create reusable starting points for sandboxes, but they solve different problems.
172+
173+
| | Templates | Snapshots |
174+
|---|---|---|
175+
| Defined by | Declarative code (Template builder) | Capturing a running sandbox |
176+
| Reproducibility | Same definition produces the same sandbox every time | Captures whatever state exists at that moment |
177+
| Best for | Repeatable base environments | Checkpointing, rollback, forking runtime state |
178+
179+
Use templates when every sandbox should start from an identical, known state — pre-installed tools, fixed configurations, consistent environments.
180+
Use snapshots when you need to capture or fork live runtime state that depends on what happened during execution.
181+
182+
## Use cases
183+
184+
- **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.
185+
- **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.
186+
- **Forking workflows** — spawn multiple sandboxes from the same snapshot to explore different approaches in parallel.
187+
- **Cached sandboxes** — avoid repeating expensive setup by snapshotting a sandbox that has already loaded a large dataset or started a long-running process.
188+
- **Sharing state** — one user or agent configures an environment interactively, snapshots it, and others start from that exact state.

images/diagram.png

-64.7 KB
Binary file not shown.

style.css

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,15 @@ code {
4747
/* orange-500 at 10% opacity */
4848
}
4949

50-
/* Icon color */
51-
.callout .text-sky-500 {
52-
color: #ff8800;
53-
}
54-
55-
/* Content text color */
56-
.callout .text-sky-900 {
50+
/* Note callout text & icon colors - light mode */
51+
.callout[data-callout-type="note"],
52+
.callout[data-callout-type="note"] *:not(a) {
5753
color: rgb(124 45 18) !important;
58-
/* orange-900 */
5954
}
6055

61-
.dark\:text-sky-200:is(.dark *) {
56+
/* Note callout text & icon colors - dark mode */
57+
.dark .callout[data-callout-type="note"],
58+
.dark .callout[data-callout-type="note"] *:not(a) {
6259
color: rgb(255, 183, 102) !important;
6360
}
6461

0 commit comments

Comments
 (0)