Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions docs/sandbox/auto-resume.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@

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

## Timeout after auto-resume

When a sandbox auto-resumes, it starts a **new timeout equal to the original timeout set at creation**.
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 10-minute timeout:

1. The sandbox runs for 10 minutes, then pauses.
2. Activity arrives and the sandbox auto-resumes.
3. A fresh 10-minute timeout starts.
4. If no further activity resets the timeout, the sandbox pauses again after 10 minutes.

This cycle repeats every time the sandbox auto-resumes — the lifecycle configuration (`onTimeout: "pause"` + `autoResume: true`) is persistent across pause/resume cycles.

<Note>
You can change the timeout after the sandbox resumes by calling `setTimeout`/`set_timeout`. See [Change sandbox timeout during runtime](/docs/sandbox#change-sandbox-timeout-during-runtime).
</Note>

## What counts as activity

Auto-resume is triggered by the sandbox activity - that's both HTTP traffic and controlling the sandbox from the SDK.
Expand Down Expand Up @@ -152,7 +170,7 @@

await new Promise((resolve) => setTimeout(resolve, 1000))

const previewHost = sandbox.getHost(3000)

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L173

Did you really mean 'previewHost'?
console.log(`Preview URL: https://${previewHost}`)

console.log(`Status before pause: ${(await sandbox.getInfo()).state}`)
Expand Down Expand Up @@ -254,7 +272,7 @@
```js JavaScript & TypeScript
import { Sandbox } from 'e2b'

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

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L275

Did you really mean 'userSandboxes'?

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L275

Did you really mean 'userId'?

async function getSandbox(userId) {
let sandbox = userSandboxes.get(userId)
Expand Down Expand Up @@ -304,5 +322,6 @@

## Cleanup
Auto-resume is persistent, meaning if your sandbox resumes and later times out again, it will pause again.
Each time the sandbox resumes, the original timeout resets — 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.
2 changes: 1 addition & 1 deletion docs/sandbox/persistence.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
```js JavaScript & TypeScript highlight={8-9}
import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()

Check warning on line 79 in docs/sandbox/persistence.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/persistence.mdx#L79

Did you really mean 'sbx'?
console.log('Sandbox created', sbx.sandboxId)

// Pause the sandbox
Expand Down Expand Up @@ -106,7 +106,7 @@
```js JavaScript & TypeScript highlight={12-13}
import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()

Check warning on line 109 in docs/sandbox/persistence.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/persistence.mdx#L109

Did you really mean 'sbx'?
console.log('Sandbox created', sbx.sandboxId)

// Pause the sandbox
Expand All @@ -115,7 +115,7 @@
console.log('Sandbox paused', sbx.sandboxId)

// Connect to the sandbox (it will automatically resume the sandbox, if paused)
const sameSbx = await sbx.connect()

Check warning on line 118 in docs/sandbox/persistence.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/persistence.mdx#L118

Did you really mean 'sameSbx'?
console.log('Connected to the sandbox', sameSbx.sandboxId)
```
```python Python highlight={12-13}
Expand Down Expand Up @@ -144,7 +144,7 @@
import { Sandbox, SandboxInfo } from '@e2b/code-interpreter'

// List all paused sandboxes
const paginator = Sandbox.list({ query: { state: ['paused'] } })

Check warning on line 147 in docs/sandbox/persistence.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/persistence.mdx#L147

Did you really mean 'paginator'?

// Get the first page of paused sandboxes
const sandboxes = await paginator.nextItems()
Expand Down Expand Up @@ -179,7 +179,7 @@
```js JavaScript & TypeScript highlight={11,14}
import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()

Check warning on line 182 in docs/sandbox/persistence.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/persistence.mdx#L182

Did you really mean 'sbx'?
console.log('Sandbox created', sbx.sandboxId)

// Pause the sandbox
Expand Down Expand Up @@ -209,13 +209,13 @@
</CodeGroup>

## Sandbox's timeout
When you connect to a sandbox, the inactivity timeout resets. The default is 5 minutes, but you can pass a custom timeout to the `Sandbox.connect()` method:
When you connect to a sandbox (or it auto-resumes), the timeout resets to the value originally set at creation time. The default is 5 minutes, but you can pass a custom timeout to the `Sandbox.connect()` method:

<CodeGroup>
```js JavaScript & TypeScript
import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.connect(sandboxId, { timeoutMs: 60 * 1000 }) // 60 seconds

Check warning on line 218 in docs/sandbox/persistence.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/persistence.mdx#L218

Did you really mean 'sbx'?
```
```python Python
from e2b_code_interpreter import Sandbox
Expand Down
Loading