Skip to content

Commit 8a524ef

Browse files
committed
Add sandbox snapshots documentation
- New docs/sandbox/snapshots.mdx page covering create, list, delete snapshots - Add snapshots to sidebar navigation - Update persistence page: replace PNG diagram with Mermaid flowchart including Snapshotting state - Remove unused images/diagram.png - Add .tool-versions for mise (Node 24.11.0)
1 parent 291102d commit 8a524ef

5 files changed

Lines changed: 182 additions & 3 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
@@ -89,6 +89,7 @@
8989
"docs/sandbox/lifecycle-events-api",
9090
"docs/sandbox/lifecycle-events-webhooks",
9191
"docs/sandbox/persistence",
92+
"docs/sandbox/snapshots",
9293
"docs/sandbox/git-integration",
9394
"docs/sandbox/metrics",
9495
"docs/sandbox/metadata",

docs/sandbox/persistence.mdx

Lines changed: 17 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
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

docs/sandbox/snapshots.mdx

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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 keeps running |
16+
| Relationship | 1:1 — resume restores the same sandbox | 1: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
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.
34+
35+
## Create a snapshot
36+
37+
You can create a snapshot from a running sandbox instance.
38+
39+
<CodeGroup>
40+
```js JavaScript & TypeScript
41+
import { Sandbox } from '@e2b/code-interpreter'
42+
43+
const sandbox = await Sandbox.create()
44+
45+
// Create a snapshot from a running sandbox
46+
const snapshot = await sandbox.createSnapshot()
47+
console.log('Snapshot ID:', snapshot.snapshotId)
48+
```
49+
```python Python
50+
from e2b_code_interpreter import Sandbox
51+
52+
sandbox = Sandbox.create()
53+
54+
# Create a snapshot from a running sandbox
55+
snapshot = sandbox.create_snapshot()
56+
print('Snapshot ID:', snapshot.snapshot_id)
57+
```
58+
</CodeGroup>
59+
60+
You can also create a snapshot by sandbox ID using the static method.
61+
62+
<CodeGroup>
63+
```js JavaScript & TypeScript
64+
import { Sandbox } from '@e2b/code-interpreter'
65+
66+
// Create a snapshot by sandbox ID
67+
const snapshot = await Sandbox.createSnapshot(sandboxId)
68+
console.log('Snapshot ID:', snapshot.snapshotId)
69+
```
70+
```python Python
71+
from e2b_code_interpreter import Sandbox
72+
73+
# Create a snapshot by sandbox ID
74+
snapshot = Sandbox.create_snapshot(sandbox_id)
75+
print('Snapshot ID:', snapshot.snapshot_id)
76+
```
77+
</CodeGroup>
78+
79+
## Create a sandbox from a snapshot
80+
81+
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.
82+
83+
<CodeGroup>
84+
```js JavaScript & TypeScript highlight={5}
85+
import { Sandbox } from '@e2b/code-interpreter'
86+
87+
const snapshot = await sandbox.createSnapshot()
88+
89+
// Create a new sandbox from the snapshot
90+
const newSandbox = await Sandbox.create(snapshot.snapshotId)
91+
```
92+
```python Python highlight={5}
93+
from e2b_code_interpreter import Sandbox
94+
95+
snapshot = sandbox.create_snapshot()
96+
97+
# Create a new sandbox from the snapshot
98+
new_sandbox = Sandbox.create(snapshot.snapshot_id)
99+
```
100+
</CodeGroup>
101+
102+
## List snapshots
103+
104+
You can list all snapshots. The method returns a paginator for iterating through results.
105+
106+
<CodeGroup>
107+
```js JavaScript & TypeScript
108+
import { Sandbox } from '@e2b/code-interpreter'
109+
110+
const paginator = Sandbox.listSnapshots()
111+
112+
const snapshots = []
113+
while (paginator.hasNext) {
114+
const items = await paginator.nextItems()
115+
snapshots.push(...items)
116+
}
117+
```
118+
```python Python
119+
from e2b_code_interpreter import Sandbox
120+
121+
paginator = Sandbox.list_snapshots()
122+
123+
snapshots = []
124+
while paginator.has_next:
125+
items = paginator.next_items()
126+
snapshots.extend(items)
127+
```
128+
</CodeGroup>
129+
130+
### Filter by sandbox
131+
132+
You can filter snapshots created from a specific sandbox.
133+
134+
<CodeGroup>
135+
```js JavaScript & TypeScript
136+
import { Sandbox } from '@e2b/code-interpreter'
137+
138+
const paginator = Sandbox.listSnapshots({ sandboxId: 'your-sandbox-id' })
139+
const snapshots = await paginator.nextItems()
140+
```
141+
```python Python
142+
from e2b_code_interpreter import Sandbox
143+
144+
paginator = Sandbox.list_snapshots(sandbox_id="your-sandbox-id")
145+
snapshots = paginator.next_items()
146+
```
147+
</CodeGroup>
148+
149+
## Delete a snapshot
150+
151+
<CodeGroup>
152+
```js JavaScript & TypeScript
153+
import { Sandbox } from '@e2b/code-interpreter'
154+
155+
// Returns true if deleted, false if the snapshot was not found
156+
const deleted = await Sandbox.deleteSnapshot(snapshot.snapshotId)
157+
```
158+
```python Python
159+
from e2b_code_interpreter import Sandbox
160+
161+
Sandbox.delete_snapshot(snapshot.snapshot_id)
162+
```
163+
</CodeGroup>

images/diagram.png

-64.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)