Skip to content
Merged
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
22 changes: 21 additions & 1 deletion docs/sandbox/auto-resume.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@

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

## Timeout after auto-resume

When a sandbox auto-resumes, it restarts with a **5-minute minimum timeout**. If you originally created the sandbox with a longer timeout, that value carries over.
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 2-minute timeout:

1. The sandbox runs for 2 minutes, then pauses.
2. Activity arrives and the sandbox auto-resumes.
3. A 5-minute timeout starts (the 5-minute minimum applies because the original timeout was shorter).
4. If no further activity resets the timeout, the sandbox pauses again after 5 minutes.

If you create a sandbox with a 1-hour timeout, the auto-resume timeout will also be 1 hour, since it exceeds the 5-minute minimum.

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 +172,7 @@

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

const previewHost = sandbox.getHost(3000)

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L175

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 +274,7 @@
```js JavaScript & TypeScript
import { Sandbox } from 'e2b'

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

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L277

Did you really mean 'userSandboxes'?

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L277

Did you really mean 'userId'?

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

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

Each time the sandbox resumes, it gets a fresh timeout (at least 5 minutes, or longer if the original creation timeout exceeds that) — 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, the timeout resets. 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