Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
deed6d1
start on auto-resume docs
matthewlouisbrockman Feb 20, 2026
9bd568b
update auto-pause docs
matthewlouisbrockman Feb 20, 2026
e080cc1
people can figure out autopause is deprecated
matthewlouisbrockman Feb 20, 2026
c1e446d
update with use cases
matthewlouisbrockman Feb 20, 2026
dc25731
add intro
matthewlouisbrockman Feb 20, 2026
b3d3616
update intro
matthewlouisbrockman Feb 20, 2026
0cd1896
update use cases
matthewlouisbrockman Feb 20, 2026
74a11e4
fix indented list
matthewlouisbrockman Feb 20, 2026
08ad76d
example for web server user case
matthewlouisbrockman Feb 20, 2026
2452cc2
add dev server to it
matthewlouisbrockman Feb 20, 2026
3dcfa22
clean up agent example
matthewlouisbrockman Feb 20, 2026
6642d71
per user sandbox example
matthewlouisbrockman Feb 20, 2026
819e560
update intro again
matthewlouisbrockman Feb 20, 2026
e2871f7
rm emdash
matthewlouisbrockman Feb 20, 2026
a9a1620
more em dashes
matthewlouisbrockman Feb 20, 2026
ba3b8bc
rm the beta notations on pause
matthewlouisbrockman Feb 20, 2026
d788c75
switch resumeOn:enum to autoResume:bool in docs
matthewlouisbrockman Feb 23, 2026
8c23c06
Merge branch 'main' into auto-resume-docs
matthewlouisbrockman Feb 24, 2026
83a3491
call it developer preview as a middle ground for the pricing not figu…
matthewlouisbrockman Feb 27, 2026
61c8978
Merge branch 'main' into auto-resume-docs
matthewlouisbrockman Feb 27, 2026
3785ffc
wording on auto-resume
matthewlouisbrockman Mar 10, 2026
081d3e6
Merge branch 'main' into auto-resume-docs
matthewlouisbrockman Mar 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"docs/sandbox/lifecycle-events-webhooks",
"docs/sandbox/persistence",
"docs/sandbox/snapshots",
"docs/sandbox/auto-resume",
"docs/sandbox/git-integration",
"docs/sandbox/metrics",
"docs/sandbox/metadata",
Expand Down
2 changes: 1 addition & 1 deletion docs/agents/amp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

const sandbox = await Sandbox.create('amp', {
envs: { AMP_API_KEY: process.env.AMP_API_KEY },
timeoutMs: 600_000,

Check warning on line 67 in docs/agents/amp.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/amp.mdx#L67

Did you really mean 'timeoutMs'?
})

await sandbox.git.clone('https://github.com/your-org/your-repo.git', {
Expand Down Expand Up @@ -180,7 +180,7 @@

const sandbox = await Sandbox.create('amp', {
envs: { AMP_API_KEY: process.env.AMP_API_KEY },
timeoutMs: 600_000,

Check warning on line 183 in docs/agents/amp.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/amp.mdx#L183

Did you really mean 'timeoutMs'?
})

// Start a new thread
Expand All @@ -191,7 +191,7 @@

// List threads and get the most recent thread ID
const threads = await sandbox.commands.run('amp threads list --json')
const threadId = JSON.parse(threads.stdout)[0].id

Check warning on line 194 in docs/agents/amp.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/amp.mdx#L194

Did you really mean 'threadId'?

// Continue the thread with a follow-up task
const followUp = await sandbox.commands.run(
Expand Down Expand Up @@ -288,7 +288,7 @@

<CodeGroup>
```bash JavaScript & TypeScript
npx tsx build.ts

Check warning on line 291 in docs/agents/amp.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/amp.mdx#L291

Did you really mean 'npx'?
```
```bash Python
python build.py
Expand All @@ -299,10 +299,10 @@

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

Check warning on line 305 in docs/agents/amp.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/amp.mdx#L305

Did you really mean 'repos'?
</Card>
<Card title="SSH access" icon="terminal" href="/docs/sandbox/ssh-access">
Connect to the sandbox via SSH for interactive sessions
Expand Down
2 changes: 1 addition & 1 deletion docs/agents/claude-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
icon: "/images/icons/claude-code.svg"
---

[Claude Code](https://docs.anthropic.com/en/docs/claude-code) is Anthropic's agentic coding tool. E2B provides a pre-built `claude` template with Claude Code already installed.

Check warning on line 7 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L7

Did you really mean 'Anthropic's'?

Check warning on line 7 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L7

Did you really mean 'agentic'?

## CLI

Expand Down Expand Up @@ -64,7 +64,7 @@

const sandbox = await Sandbox.create('claude', {
envs: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
timeoutMs: 600_000,

Check warning on line 67 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L67

Did you really mean 'timeoutMs'?
})

await sandbox.git.clone('https://github.com/your-org/your-repo.git', {
Expand Down Expand Up @@ -220,7 +220,7 @@

const sandbox = await Sandbox.create('claude', {
envs: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
timeoutMs: 600_000,

Check warning on line 223 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L223

Did you really mean 'timeoutMs'?
})

// Start a new session
Expand All @@ -230,7 +230,7 @@

// Extract session ID from the JSON response
const response = JSON.parse(initial.stdout)
const sessionId = response.session_id

Check warning on line 233 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L233

Did you really mean 'sessionId'?

// Continue with a follow-up task
const followUp = await sandbox.commands.run(
Expand Down Expand Up @@ -334,7 +334,7 @@

const sandbox = await Sandbox.create('claude', {
envs: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
mcp: {

Check warning on line 337 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L337

Did you really mean 'mcp'?
browserbase: {
apiKey: process.env.BROWSERBASE_API_KEY,
projectId: process.env.BROWSERBASE_PROJECT_ID,
Expand All @@ -342,8 +342,8 @@
},
})

const mcpUrl = sandbox.getMcpUrl()

Check warning on line 345 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L345

Did you really mean 'mcpUrl'?
const mcpToken = await sandbox.getMcpToken()

Check warning on line 346 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L346

Did you really mean 'mcpToken'?

await sandbox.commands.run(
`claude mcp add --transport http e2b-mcp-gateway ${mcpUrl} --header "Authorization: Bearer ${mcpToken}"`
Expand Down Expand Up @@ -437,7 +437,7 @@

<CodeGroup>
```bash JavaScript & TypeScript
npx tsx build.ts

Check warning on line 440 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L440

Did you really mean 'npx'?
```
```bash Python
python build.py
Expand All @@ -451,9 +451,9 @@
Connect Claude Code to 200+ MCP tools
</Card>
<Card title="Sandbox persistence" icon="clock" href="/docs/sandbox/persistence">
Auto-pause, resume, and manage sandbox lifecycle
Developer Preview: auto-pause, resume, and manage sandbox lifecycle
</Card>
<Card title="Git integration" icon="code-branch" href="/docs/sandbox/git-integration">
Clone repos, manage branches, and push changes

Check warning on line 457 in docs/agents/claude-code.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/claude-code.mdx#L457

Did you really mean 'repos'?
</Card>
</CardGroup>
2 changes: 1 addition & 1 deletion docs/agents/codex.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

const sandbox = await Sandbox.create('codex', {
envs: { CODEX_API_KEY: process.env.CODEX_API_KEY },
timeoutMs: 600_000,

Check warning on line 69 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L69

Did you really mean 'timeoutMs'?
})

await sandbox.git.clone('https://github.com/your-org/your-repo.git', {
Expand Down Expand Up @@ -246,19 +246,19 @@

## Image input

Pass screenshots or design mockups with `--image` to give Codex visual context alongside the prompt.

Check warning on line 249 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L249

Did you really mean 'mockups'?

<CodeGroup>
```typescript JavaScript & TypeScript
import fs from 'fs'

Check warning on line 253 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L253

Did you really mean 'fs'?
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('codex', {
envs: { CODEX_API_KEY: process.env.CODEX_API_KEY },
timeoutMs: 600_000,

Check warning on line 258 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L258

Did you really mean 'timeoutMs'?
})

// Upload a design mockup to the sandbox

Check warning on line 261 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L261

Did you really mean 'mockup'?
await sandbox.files.write(
'/home/user/mockup.png',
fs.readFileSync('./mockup.png')
Expand Down Expand Up @@ -344,7 +344,7 @@

<CodeGroup>
```bash JavaScript & TypeScript
npx tsx build.ts

Check warning on line 347 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L347

Did you really mean 'npx'?
```
```bash Python
python build.py
Expand All @@ -355,10 +355,10 @@

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

Check warning on line 361 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L361

Did you really mean 'repos'?
</Card>
<Card title="SSH access" icon="terminal" href="/docs/sandbox/ssh-access">
Connect to the sandbox via SSH for interactive sessions
Expand Down
8 changes: 4 additions & 4 deletions docs/agents/openclaw.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

const sandbox = await Sandbox.create('openclaw', {
envs: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
timeoutMs: 600_000,

Check warning on line 67 in docs/agents/openclaw.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/openclaw.mdx#L67

Did you really mean 'timeoutMs'?
})

await sandbox.git.clone('https://github.com/your-org/your-repo.git', {
Expand Down Expand Up @@ -168,7 +168,7 @@
# Soul

## Core Truths
- Be genuinely helpful, not performatively helpful

Check warning on line 171 in docs/agents/openclaw.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/openclaw.mdx#L171

Did you really mean 'performatively'?
- Be resourceful before asking — check the workspace, search the web, read docs

## Boundaries
Expand Down Expand Up @@ -386,9 +386,9 @@

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.

<Warning>
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.
</Warning>
<Warning>
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.
</Warning>

<CodeGroup>
```typescript JavaScript & TypeScript
Expand All @@ -396,8 +396,8 @@

const sandbox = await Sandbox.betaCreate('openclaw', {
envs: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
autoPause: true,

Check warning on line 399 in docs/agents/openclaw.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/openclaw.mdx#L399

Did you really mean 'autoPause'?
timeoutMs: 10 * 60 * 1000,

Check warning on line 400 in docs/agents/openclaw.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/openclaw.mdx#L400

Did you really mean 'timeoutMs'?
})

// Start the gateway
Expand Down Expand Up @@ -436,7 +436,7 @@
import { Template, waitForPort } from 'e2b'

export const template = Template()
.fromTemplate('openclaw')

Check warning on line 439 in docs/agents/openclaw.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/openclaw.mdx#L439

Did you really mean 'openclaw'?
// Optional - start the OpenClaw gateway on sandbox start
.setStartCmd(
'openclaw gateway --port 18789 --verbose',
Expand Down Expand Up @@ -488,7 +488,7 @@

<CodeGroup>
```bash JavaScript & TypeScript
npx tsx build.ts

Check warning on line 491 in docs/agents/openclaw.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/openclaw.mdx#L491

Did you really mean 'npx'?
```
```bash Python
python build.py
Expand All @@ -499,10 +499,10 @@

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

Check warning on line 505 in docs/agents/openclaw.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/openclaw.mdx#L505

Did you really mean 'repos'?
</Card>
<Card title="SSH access" icon="terminal" href="/docs/sandbox/ssh-access">
Connect to the sandbox via SSH for interactive sessions
Expand Down
2 changes: 1 addition & 1 deletion docs/agents/opencode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

const sandbox = await Sandbox.create('opencode', {
envs: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
timeoutMs: 600_000,

Check warning on line 67 in docs/agents/opencode.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/opencode.mdx#L67

Did you really mean 'timeoutMs'?
})

await sandbox.git.clone('https://github.com/your-org/your-repo.git', {
Expand Down Expand Up @@ -122,8 +122,8 @@

const sandbox = await Sandbox.betaCreate('opencode', {
envs: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
autoPause: true,

Check warning on line 125 in docs/agents/opencode.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/opencode.mdx#L125

Did you really mean 'autoPause'?
timeoutMs: 10 * 60 * 1000,

Check warning on line 126 in docs/agents/opencode.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/opencode.mdx#L126

Did you really mean 'timeoutMs'?
})

// Start the OpenCode server
Expand All @@ -133,7 +133,7 @@

// Wait for the server to be ready
const host = sandbox.getHost(4096)
const baseUrl = `https://${host}`

Check warning on line 136 in docs/agents/opencode.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/opencode.mdx#L136

Did you really mean 'baseUrl'?
while (true) {
try {
await fetch(`${baseUrl}/global/health`)
Expand Down Expand Up @@ -208,7 +208,7 @@
import { Template, waitForPort } from 'e2b'

export const template = Template()
.fromTemplate('opencode')

Check warning on line 211 in docs/agents/opencode.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/opencode.mdx#L211

Did you really mean 'opencode'?
.setEnvs({
OPENCODE_SERVER_PASSWORD: 'your-password',
})
Expand Down Expand Up @@ -266,7 +266,7 @@

<CodeGroup>
```bash JavaScript & TypeScript
npx tsx build.ts

Check warning on line 269 in docs/agents/opencode.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/opencode.mdx#L269

Did you really mean 'npx'?
```
```bash Python
python build.py
Expand All @@ -277,10 +277,10 @@

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

Check warning on line 283 in docs/agents/opencode.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/opencode.mdx#L283

Did you really mean 'repos'?
</Card>
<Card title="SSH access" icon="terminal" href="/docs/sandbox/ssh-access">
Connect to the sandbox via SSH for interactive sessions
Expand Down
2 changes: 1 addition & 1 deletion docs/sandbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sidebarTitle: Lifecycle
---

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.
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.

<Note>
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.
Expand Down Expand Up @@ -84,8 +84,8 @@
// "templateId": "rki5dems9wqfm4r03t7g",
// "name": "base",
// "metadata": {},
// "startedAt": "2025-03-24T15:37:58.076Z",

Check warning on line 87 in docs/sandbox.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox.mdx#L87

Did you really mean 'startedAt'?
// "endAt": "2025-03-24T15:42:58.076Z"

Check warning on line 88 in docs/sandbox.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox.mdx#L88

Did you really mean 'endAt'?
// }
```

Expand Down
222 changes: 222 additions & 0 deletions docs/sandbox/auto-resume.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
---
title: "AutoResume"
sidebarTitle: AutoResume
---

<Note>
`AutoResume` and `pause/resume` persistence are available as **Developer Preview**.

Behavior and limits may change as we iterate. Review [Sandbox persistence limitations](/docs/sandbox/persistence#current-limitations-subject-to-change).
</Note>

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.

`AutoResume` handles this automatically: a paused sandbox wakes up when activity arrives, so your code does not have to check or manage sandbox state.
Configure it through the `lifecycle` object when creating a sandbox.

## Configure lifecycle on create

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create({
timeoutMs: 10 * 60 * 1000,
lifecycle: {
onTimeout: 'pause',
autoResume: true, // resume when traffic arrives
},
})
```
```python Python
from e2b import Sandbox

sandbox = Sandbox.create(
timeout=10 * 60,
lifecycle={
"on_timeout": "pause",
"auto_resume": True, # resume when traffic arrives
},
)
```
</CodeGroup>

## Lifecycle options

- `onTimeout` / `on_timeout`
- `kill` (default): sandbox is terminated when timeout is reached
- `pause`: sandbox is paused when timeout is reached
- `autoResume` / `auto_resume`
- `false` (default): paused sandboxes do not auto-resume
- `true`: paused sandboxes auto-resume on activity
- `true` is valid only when `onTimeout`/`on_timeout` is `pause`

## Behavior summary

- Default behavior is equivalent to `onTimeout: "kill"` with `autoResume: false`.
- `onTimeout: "pause"` with `autoResume: false` gives auto-pause without auto-resume.
- `onTimeout: "pause"` with `autoResume: true` gives auto-pause with auto-resume.
- [`Sandbox.connect()`](/docs/sandbox/connect) can still be used to resume a paused sandbox manually.

If you use `autoResume: false`, resume explicitly with [`Sandbox.connect()`](/docs/sandbox/connect).

## Use cases

### Web and dev/preview servers

Use `onTimeout: "pause"` + `autoResume: true` so inbound traffic can wake a paused sandbox automatically.
This works for both:
- Basic web/API servers
- Dev or preview servers you open occasionally

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create({
timeoutMs: 10 * 60 * 1000,
lifecycle: {
onTimeout: 'pause',
autoResume: true,
},
})

// Example: app source already exists in /home/user/app.
// Replace this command with your API server, Next.js, Vite, etc.
await sandbox.commands.run(
'cd /home/user/app && npm install && npm run dev -- --host 0.0.0.0 --port 3000',
{ background: true }
)

const previewHost = sandbox.getHost(3000)

Check warning on line 91 in docs/sandbox/auto-resume.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L91

Did you really mean 'previewHost'?
console.log(`Preview URL: https://${previewHost}`)
```
```python Python
from e2b import Sandbox

sandbox = Sandbox.create(
timeout=10 * 60,
lifecycle={
"on_timeout": "pause",
"auto_resume": True,
},
)

# Example: app source already exists in /home/user/app.
# Replace this command with your API server, Next.js, Vite, etc.
sandbox.commands.run(
"cd /home/user/app && npm install && npm run dev -- --host 0.0.0.0 --port 3000",
background=True,
)

preview_host = sandbox.get_host(3000)
print(f"Preview URL: https://{preview_host}")
```
</CodeGroup>

### 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.

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from 'e2b'

// One-time setup
const sandbox = await Sandbox.create({
timeoutMs: 5 * 60 * 1000,
lifecycle: {
onTimeout: 'pause',
autoResume: true,
},
})

// Later: called for each agent/tool task
async function runToolTask(command) {
const result = await sandbox.commands.run(command)
return result.stdout
}

console.log(await runToolTask('python -c "print(2 + 2)"'))
```
```python Python
from e2b import Sandbox

# One-time setup
sandbox = Sandbox.create(
timeout=5 * 60,
lifecycle={
"on_timeout": "pause",
"auto_resume": True,
},
)

# Later: called for each agent/tool task
def run_tool_task(command: str) -> str:
result = sandbox.commands.run(command)
return result.stdout

print(run_tool_task('python -c "print(2 + 2)"'))
```
</CodeGroup>

### 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.

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from 'e2b'

const userSandboxes = new Map() // userId → Sandbox

Check warning on line 171 in docs/sandbox/auto-resume.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L171

Did you really mean 'userSandboxes'?

Check warning on line 171 in docs/sandbox/auto-resume.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L171

Did you really mean 'userId'?

async function getSandbox(userId) {
let sandbox = userSandboxes.get(userId)

if (!sandbox) {
sandbox = await Sandbox.create({
timeoutMs: 5 * 60 * 1000,
lifecycle: {
onTimeout: 'pause',
autoResume: true,
},
})
userSandboxes.set(userId, sandbox)
}

return sandbox
}

// On each user request (auto-resumes if paused)
const sandbox = await getSandbox('user-123')
const result = await sandbox.commands.run('echo "Hello from your sandbox"')
console.log(result.stdout)
```
```python Python
from e2b import Sandbox

user_sandboxes: dict[str, Sandbox] = {} # user_id → Sandbox

def get_sandbox(user_id: str) -> Sandbox:
if user_id not in user_sandboxes:
user_sandboxes[user_id] = Sandbox.create(
timeout=5 * 60,
lifecycle={
"on_timeout": "pause",
"auto_resume": True,
},
)

return user_sandboxes[user_id]

# On each user request (auto-resumes if paused)
sandbox = get_sandbox("user-123")
result = sandbox.commands.run('echo "Hello from your sandbox"')
print(result.stdout)
```
</CodeGroup>

## Cleanup
Auto-resume is persistent, meaning if your sandbox resumes and later times out again, it will pause again.

If you call `.kill()`, the sandbox is permanently deleted and cannot be resumed.
Loading
Loading