Skip to main content
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 doesn’t have to check or manage sandbox state. AutoResume builds on the sandbox persistence lifecycle.

Configure AutoResume

Set the lifecycle object when creating a sandbox to control what happens on timeout and whether paused sandboxes should auto-resume.
import { Sandbox } from 'e2b'

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

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
AutoResume is persistent — if a sandbox resumes and later times out again, it will pause again automatically. To permanently delete a sandbox, call .kill(). A killed sandbox cannot be resumed. If autoResume is false, you can still resume a paused sandbox manually with Sandbox.connect().

What counts as activity

Auto-resume is triggered by sandbox activity — both HTTP traffic and SDK operations. That includes:
  • 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() first.

SDK example: pause, then read a file

The following example writes a file, pauses the sandbox, then reads the file back. The read operation triggers an automatic resume.
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}`)

Example: Web server with AutoResume

AutoResume is especially useful for web servers and preview environments. When an HTTP request arrives at a paused sandbox, the sandbox wakes up automatically to handle it. The following example starts a simple HTTP server and retrieves its public URL. Use getHost() / get_host() to get the sandbox’s publicly accessible hostname for a given port.
import { Sandbox } from 'e2b'

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

await sandbox.commands.run('python3 -m http.server 3000', { background: true })

const host = sandbox.getHost(3000)
console.log(`Preview URL: https://${host}`)
Once the sandbox times out and pauses, any request to the preview URL will automatically resume it.