Skip to content

Commit ac188ed

Browse files
AutoResume Docs (#123)
pushing autoresume docs live. continuing to update as get feedback on what parameters to expose.
1 parent fdca405 commit ac188ed

File tree

11 files changed

+266
-37
lines changed

11 files changed

+266
-37
lines changed

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"docs/sandbox/lifecycle-events-webhooks",
109109
"docs/sandbox/persistence",
110110
"docs/sandbox/snapshots",
111+
"docs/sandbox/auto-resume",
111112
"docs/sandbox/git-integration",
112113
"docs/sandbox/metrics",
113114
"docs/sandbox/metadata",

docs/agents/amp.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ python build.py
299299

300300
<CardGroup cols={3}>
301301
<Card title="Sandbox persistence" icon="clock" href="/docs/sandbox/persistence">
302-
Auto-pause, resume, and manage sandbox lifecycle
302+
Developer Preview: auto-pause, resume, and manage sandbox lifecycle
303303
</Card>
304304
<Card title="Git integration" icon="code-branch" href="/docs/sandbox/git-integration">
305305
Clone repos, manage branches, and push changes

docs/agents/claude-code.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ python build.py
451451
Connect Claude Code to 200+ MCP tools
452452
</Card>
453453
<Card title="Sandbox persistence" icon="clock" href="/docs/sandbox/persistence">
454-
Auto-pause, resume, and manage sandbox lifecycle
454+
Developer Preview: auto-pause, resume, and manage sandbox lifecycle
455455
</Card>
456456
<Card title="Git integration" icon="code-branch" href="/docs/sandbox/git-integration">
457457
Clone repos, manage branches, and push changes

docs/agents/codex.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ python build.py
355355

356356
<CardGroup cols={3}>
357357
<Card title="Sandbox persistence" icon="clock" href="/docs/sandbox/persistence">
358-
Auto-pause, resume, and manage sandbox lifecycle
358+
Developer Preview: auto-pause, resume, and manage sandbox lifecycle
359359
</Card>
360360
<Card title="Git integration" icon="code-branch" href="/docs/sandbox/git-integration">
361361
Clone repos, manage branches, and push changes

docs/agents/openclaw.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ sandbox.kill()
386386

387387
OpenClaw has a built-in [web UI and chat interface](https://openclaw.ai) served by its gateway. Start it inside a sandbox and connect from your browser.
388388

389-
<Warning>
390-
This sandbox is created with a 10-minute timeout and auto-pause enabled — after 10 minutes of inactivity it pauses and can be resumed later. See [Sandbox Persistence](/docs/sandbox/persistence) and [Sandbox Lifecycle](/docs/sandbox) for more details.
391-
</Warning>
389+
<Warning>
390+
This sandbox is created with a 10-minute timeout and auto-pause enabled. After 10 minutes of inactivity it pauses and can be resumed later. Pause/resume persistence and auto-resume are currently in **Developer Preview**. See [Sandbox Persistence](/docs/sandbox/persistence) and [Sandbox Lifecycle](/docs/sandbox) for more details.
391+
</Warning>
392392

393393
<CodeGroup>
394394
```typescript JavaScript & TypeScript
@@ -499,7 +499,7 @@ python build.py
499499

500500
<CardGroup cols={3}>
501501
<Card title="Sandbox persistence" icon="clock" href="/docs/sandbox/persistence">
502-
Auto-pause, resume, and manage sandbox lifecycle
502+
Developer Preview: auto-pause, resume, and manage sandbox lifecycle
503503
</Card>
504504
<Card title="Git integration" icon="code-branch" href="/docs/sandbox/git-integration">
505505
Clone repos, manage branches, and push changes

docs/agents/opencode.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ python build.py
277277

278278
<CardGroup cols={3}>
279279
<Card title="Sandbox persistence" icon="clock" href="/docs/sandbox/persistence">
280-
Auto-pause, resume, and manage sandbox lifecycle
280+
Developer Preview: auto-pause, resume, and manage sandbox lifecycle
281281
</Card>
282282
<Card title="Git integration" icon="code-branch" href="/docs/sandbox/git-integration">
283283
Clone repos, manage branches, and push changes

docs/sandbox.mdx

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

6-
Sandboxes stay running as long as you need them. When their timeout expires, they automatically pause to save resources — preserving their full state so you can resume at any time. You can also configure an explicit timeout or shut down a sandbox manually.
6+
Sandboxes stay running as long as you need them. When their timeout expires, they can automatically pause to save resources — preserving their full state so you can resume at any time. You can also configure an explicit timeout or shut down a sandbox manually.
77

88
<Note>
99
Sandboxes can run continuously for up to 24 hours (Pro) or 1 hour (Base). For longer workloads, use [pause and resume](/docs/sandbox/persistence) — pausing resets the runtime window, and your sandbox's full state is preserved indefinitely.

docs/sandbox/auto-resume.mdx

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
---
2+
title: "AutoResume"
3+
sidebarTitle: AutoResume
4+
---
5+
6+
<Note>
7+
`AutoResume` and `pause/resume` persistence are available as **Developer Preview**.
8+
9+
Behavior and limits may change as we iterate. Review [Sandbox persistence limitations](/docs/sandbox/persistence#current-limitations-subject-to-change).
10+
</Note>
11+
12+
Many workloads don't need a sandbox running all the time, but when they do need it, it should just work, whether it was paused or not.
13+
14+
`AutoResume` handles this automatically: a paused sandbox wakes up when activity arrives, so your code does not have to check or manage sandbox state.
15+
Configure it through the `lifecycle` object when creating a sandbox.
16+
17+
## Configure lifecycle on create
18+
19+
<CodeGroup>
20+
```js JavaScript & TypeScript
21+
import { Sandbox } from 'e2b'
22+
23+
const sandbox = await Sandbox.create({
24+
timeoutMs: 10 * 60 * 1000,
25+
lifecycle: {
26+
onTimeout: 'pause',
27+
autoResume: true, // resume when traffic arrives
28+
},
29+
})
30+
```
31+
```python Python
32+
from e2b import Sandbox
33+
34+
sandbox = Sandbox.create(
35+
timeout=10 * 60,
36+
lifecycle={
37+
"on_timeout": "pause",
38+
"auto_resume": True, # resume when traffic arrives
39+
},
40+
)
41+
```
42+
</CodeGroup>
43+
44+
## Lifecycle options
45+
46+
- `onTimeout` / `on_timeout`
47+
- `kill` (default): sandbox is terminated when timeout is reached
48+
- `pause`: sandbox is paused when timeout is reached
49+
- `autoResume` / `auto_resume`
50+
- `false` (default): paused sandboxes do not auto-resume
51+
- `true`: paused sandboxes auto-resume on activity
52+
- `true` is valid only when `onTimeout`/`on_timeout` is `pause`
53+
54+
## Behavior summary
55+
56+
- Default behavior is equivalent to `onTimeout: "kill"` with `autoResume: false`.
57+
- `onTimeout: "pause"` with `autoResume: false` gives auto-pause without auto-resume.
58+
- `onTimeout: "pause"` with `autoResume: true` gives auto-pause with auto-resume.
59+
- [`Sandbox.connect()`](/docs/sandbox/connect) can still be used to resume a paused sandbox manually.
60+
61+
If you use `autoResume: false`, resume explicitly with [`Sandbox.connect()`](/docs/sandbox/connect).
62+
63+
## Use cases
64+
65+
### Web and dev/preview servers
66+
67+
Use `onTimeout: "pause"` + `autoResume: true` so inbound traffic can wake a paused sandbox automatically.
68+
This works for both:
69+
- Basic web/API servers
70+
- Dev or preview servers you open occasionally
71+
72+
<CodeGroup>
73+
```js JavaScript & TypeScript
74+
import { Sandbox } from 'e2b'
75+
76+
const sandbox = await Sandbox.create({
77+
timeoutMs: 10 * 60 * 1000,
78+
lifecycle: {
79+
onTimeout: 'pause',
80+
autoResume: true,
81+
},
82+
})
83+
84+
// Example: app source already exists in /home/user/app.
85+
// Replace this command with your API server, Next.js, Vite, etc.
86+
await sandbox.commands.run(
87+
'cd /home/user/app && npm install && npm run dev -- --host 0.0.0.0 --port 3000',
88+
{ background: true }
89+
)
90+
91+
const previewHost = sandbox.getHost(3000)
92+
console.log(`Preview URL: https://${previewHost}`)
93+
```
94+
```python Python
95+
from e2b import Sandbox
96+
97+
sandbox = Sandbox.create(
98+
timeout=10 * 60,
99+
lifecycle={
100+
"on_timeout": "pause",
101+
"auto_resume": True,
102+
},
103+
)
104+
105+
# Example: app source already exists in /home/user/app.
106+
# Replace this command with your API server, Next.js, Vite, etc.
107+
sandbox.commands.run(
108+
"cd /home/user/app && npm install && npm run dev -- --host 0.0.0.0 --port 3000",
109+
background=True,
110+
)
111+
112+
preview_host = sandbox.get_host(3000)
113+
print(f"Preview URL: https://{preview_host}")
114+
```
115+
</CodeGroup>
116+
117+
### Agent/tool execution
118+
119+
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.
120+
121+
<CodeGroup>
122+
```js JavaScript & TypeScript
123+
import { Sandbox } from 'e2b'
124+
125+
// One-time setup
126+
const sandbox = await Sandbox.create({
127+
timeoutMs: 5 * 60 * 1000,
128+
lifecycle: {
129+
onTimeout: 'pause',
130+
autoResume: true,
131+
},
132+
})
133+
134+
// Later: called for each agent/tool task
135+
async function runToolTask(command) {
136+
const result = await sandbox.commands.run(command)
137+
return result.stdout
138+
}
139+
140+
console.log(await runToolTask('python -c "print(2 + 2)"'))
141+
```
142+
```python Python
143+
from e2b import Sandbox
144+
145+
# One-time setup
146+
sandbox = Sandbox.create(
147+
timeout=5 * 60,
148+
lifecycle={
149+
"on_timeout": "pause",
150+
"auto_resume": True,
151+
},
152+
)
153+
154+
# Later: called for each agent/tool task
155+
def run_tool_task(command: str) -> str:
156+
result = sandbox.commands.run(command)
157+
return result.stdout
158+
159+
print(run_tool_task('python -c "print(2 + 2)"'))
160+
```
161+
</CodeGroup>
162+
163+
### Per-user sandboxes
164+
165+
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.
166+
167+
<CodeGroup>
168+
```js JavaScript & TypeScript
169+
import { Sandbox } from 'e2b'
170+
171+
const userSandboxes = new Map() // userId → Sandbox
172+
173+
async function getSandbox(userId) {
174+
let sandbox = userSandboxes.get(userId)
175+
176+
if (!sandbox) {
177+
sandbox = await Sandbox.create({
178+
timeoutMs: 5 * 60 * 1000,
179+
lifecycle: {
180+
onTimeout: 'pause',
181+
autoResume: true,
182+
},
183+
})
184+
userSandboxes.set(userId, sandbox)
185+
}
186+
187+
return sandbox
188+
}
189+
190+
// On each user request (auto-resumes if paused)
191+
const sandbox = await getSandbox('user-123')
192+
const result = await sandbox.commands.run('echo "Hello from your sandbox"')
193+
console.log(result.stdout)
194+
```
195+
```python Python
196+
from e2b import Sandbox
197+
198+
user_sandboxes: dict[str, Sandbox] = {} # user_id → Sandbox
199+
200+
def get_sandbox(user_id: str) -> Sandbox:
201+
if user_id not in user_sandboxes:
202+
user_sandboxes[user_id] = Sandbox.create(
203+
timeout=5 * 60,
204+
lifecycle={
205+
"on_timeout": "pause",
206+
"auto_resume": True,
207+
},
208+
)
209+
210+
return user_sandboxes[user_id]
211+
212+
# On each user request (auto-resumes if paused)
213+
sandbox = get_sandbox("user-123")
214+
result = sandbox.commands.run('echo "Hello from your sandbox"')
215+
print(result.stdout)
216+
```
217+
</CodeGroup>
218+
219+
## Cleanup
220+
Auto-resume is persistent, meaning if your sandbox resumes and later times out again, it will pause again.
221+
222+
If you call `.kill()`, the sandbox is permanently deleted and cannot be resumed.

0 commit comments

Comments
 (0)