Skip to content

Sandbox Lifecycle

Sandbox lifecycle management, timeouts, and information retrieval.

Default Timeout: Sandboxes stay alive for 5 minutes by default. After timeout, sandbox automatically shuts down.

Create Sandbox with Custom Timeout:

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

// Keep running for 60 seconds
// Note: Units are milliseconds
const sandbox = await Sandbox.create({
  timeoutMs: 60_000,
})

Python:

python
from e2b_code_interpreter import Sandbox

# Keep running for 60 seconds
sandbox = Sandbox.create(timeout_ms=60_000)

Change Timeout During Runtime:

When you call set timeout, the sandbox timeout resets to the new value. Useful for extending lifetime when sandbox is already running.

javascript
// Create with 60 second timeout
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

// Change to 30 seconds from now
await sandbox.setTimeout(30_000)

Python:

python
sandbox = Sandbox.create(timeout_ms=60_000)
sandbox.set_timeout(30_000)

Retrieve Sandbox Information:

javascript
const info = await sandbox.getInfo()

console.log(info)
// {
//   "sandboxId": "iiny0783cype8gmoawzmx-ce30bc46",
//   "templateId": "rki5dems9wqfm4r03t7g",
//   "name": "base",
//   "metadata": {},
//   "startedAt": "2025-03-24T15:37:58.076Z",
//   "endAt": "2025-03-24T15:42:58.076Z"
// }

Python:

python
info = sandbox.get_info()
print(info)

Shutdown Sandbox:

Shutdown any time before timeout expires.

javascript
await sandbox.kill()

Python:

python
sandbox.kill()

E2B Documentation • Generated from e2b.dev/docs