Skip to content
Open
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
57 changes: 55 additions & 2 deletions docs/sandbox/auto-resume.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
timeoutMs: 10 * 60 * 1000,
lifecycle: {
onTimeout: 'pause',
autoResume: true, // resume when traffic arrives
autoResume: true, // resume when activity arrives
},
})
```
Expand All @@ -29,7 +29,7 @@
timeout=10 * 60,
lifecycle={
"on_timeout": "pause",
"auto_resume": True, # resume when traffic arrives
"auto_resume": True, # resume when activity arrives
},
)
```
Expand All @@ -54,6 +54,59 @@

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

## What counts as activity

Auto-resume is triggered by the sandbox activity - that's both HTTP traffic and controlling the sandbox from the SDK.

That includes SDK operations like:
- `sandbox.commands.run(...)`
- `sandbox.files.read(...)`
- `sandbox.files.write(...)`
- opening a tunneled app URL or sending requests to a service running inside the sandbox

If a sandbox is paused and `autoResume` is enabled, the next supported operation resumes it automatically. You do not need to call [`Sandbox.connect()`](/docs/sandbox/connect) first.

### SDK example: pause, then read a file

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

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

await sandbox.files.write('/home/user/hello.txt', 'hello from a paused sandbox')
await sandbox.pause()

const content = await sandbox.files.read('/home/user/hello.txt')
console.log(content)
console.log(`State after read: ${(await sandbox.getInfo()).state}`)
```
```python Python
from e2b import Sandbox

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

sandbox.files.write("/home/user/hello.txt", "hello from a paused sandbox")
sandbox.pause()

content = sandbox.files.read("/home/user/hello.txt")
print(content)
print(f"State after read: {sandbox.get_info().state}")
```
</CodeGroup>

## Use cases

### Web and dev/preview servers
Expand Down Expand Up @@ -99,7 +152,7 @@

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

const previewHost = sandbox.getHost(3000)

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L155

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

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

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

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L257

Did you really mean 'userSandboxes'?

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

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/sandbox/auto-resume.mdx#L257

Did you really mean 'userId'?

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