Skip to main content
The sandbox persistence allows you to pause your sandbox and resume it later from the same state it was in when you paused it. This includes not only state of the sandbox’s filesystem but also the sandbox’s memory. This means all running processes, loaded variables, data, etc.

Sandbox state transitions

Understanding how sandboxes transition between different states is crucial for managing their lifecycle effectively. Here’s a diagram showing the possible state transitions:

State descriptions

  • Running: The sandbox is actively running and can execute code. This is the initial state after creation.
  • Paused: The sandbox execution is suspended but its state is preserved.
  • Snapshotting: The sandbox is briefly paused while a persistent snapshot is being created. It automatically returns to Running. See Snapshots.
  • Killed: The sandbox is terminated and all resources are released. This is a terminal state.

Changing sandbox’s state

import { Sandbox } from '@e2b/code-interpreter'

const sandbox = await Sandbox.create() // Starts in Running state

// Pause the sandbox
await sandbox.betaPause() // Running → Paused

// Resume the sandbox
await sandbox.connect() // Running/Paused → Running

// Kill the sandbox (from any state)
await sandbox.kill() // Running/Paused → Killed

Pausing sandbox

When you pause a sandbox, both the sandbox’s filesystem and memory state will be saved. This includes all the files in the sandbox’s filesystem and all the running processes, loaded variables, data, etc.
import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()
console.log('Sandbox created', sbx.sandboxId)

// Pause the sandbox
// You can save the sandbox ID in your database to resume the sandbox later
await sbx.betaPause()
console.log('Sandbox paused', sbx.sandboxId)

Resuming sandbox

When you resume a sandbox, it will be in the same state it was in when you paused it. This means that all the files in the sandbox’s filesystem will be restored and all the running processes, loaded variables, data, etc. will be restored.
import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()
console.log('Sandbox created', sbx.sandboxId)

// Pause the sandbox
// You can save the sandbox ID in your database to resume the sandbox later
await sbx.betaPause()
console.log('Sandbox paused', sbx.sandboxId)

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

Listing paused sandboxes

You can list all paused sandboxes by calling the Sandbox.list method and supplying the state query parameter. More information about using the method can be found in List Sandboxes.
import { Sandbox, SandboxInfo } from '@e2b/code-interpreter'

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

// Get the first page of paused sandboxes
const sandboxes = await paginator.nextItems()

// Get all paused sandboxes
while (paginator.hasNext) {
  const items = await paginator.nextItems()
  sandboxes.push(...items)
}

Removing paused sandboxes

You can remove paused sandboxes by calling the kill method on the Sandbox instance.
import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()
console.log('Sandbox created', sbx.sandboxId)

// Pause the sandbox
// You can save the sandbox ID in your database to resume the sandbox later
await sbx.betaPause()

// Remove the sandbox
await sbx.kill()

// Remove sandbox by id
await Sandbox.kill(sbx.sandboxId)

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:
import { Sandbox } from '@e2b/code-interpreter'

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

Auto-pause

Sandboxes automatically pause when their timeout expires, preserving their full state instead of shutting down. You can resume at any time from exactly where you left off. The default timeout is 10 minutes — configure it with the timeoutMs/timeout parameter.
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with auto-pause enabled
const sandbox = await Sandbox.betaCreate({
    autoPause: true,
    timeoutMs: 10 * 60 * 1000 // Optional: change the default timeout (10 minutes)
})
The auto-pause is persistent, meaning that if your sandbox resumes and it times out, it will be automatically paused again. If you .kill() the sandbox, it will be permanently deleted and you won’t be able to resume it.
import { Sandbox } from '@e2b/code-interpreter'

// Create sandbox with auto-pause enabled
const sandbox = await Sandbox.betaCreate({
    autoPause: true  // Auto-pause after the sandbox times out
})

Network

If you have a service (for example a server) running inside your sandbox and you pause the sandbox, the service won’t be accessible from the outside and all the clients will be disconnected. If you resume the sandbox, the service will be accessible again but you need to connect clients again.

Limitations

Pause and resume performance

  • Pausing a sandbox takes approximately 4 seconds per 1 GiB of RAM
  • Resuming a sandbox takes approximately 1 second

Paused sandbox retention

  • Paused sandboxes are kept indefinitely — there is no automatic deletion or time-to-live limit
  • You can resume a paused sandbox at any time

Continuous runtime limits

  • A sandbox can remain running (without being paused) for:
    • 24 hours on the Pro tier
    • 1 hour on the Base tier
  • After a sandbox is paused and resumed, the continuous runtime limit is reset