Overview

Sandbox lifecycle

Create with a timeout#

The units differ between SDKs: JavaScript takes milliseconds (timeoutMs), Python takes seconds (timeout).

import { Sandbox } from 'e2b'
 
// Keep the sandbox running for 60 seconds.
const sandbox = await Sandbox.create({
  timeoutMs: 60_000,
})
from e2b import Sandbox
 
# Keep the sandbox running for 60 seconds.
sandbox = Sandbox.create(
  timeout=60,
)

Change the timeout while it runs#

setTimeout / set_timeout resets the countdown: the new value counts from now, not from creation. Interactive apps call it on every user action to keep a sandbox alive while someone is using it.

import { Sandbox } from 'e2b'
 
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })
 
// The new timeout will be 30 seconds from now.
await sandbox.setTimeout(30_000)
from e2b import Sandbox
 
sandbox = Sandbox.create(timeout=60)
 
# The new timeout will be 30 seconds from now.
sandbox.set_timeout(30)

Read sandbox information#

import { Sandbox } from 'e2b'
 
const sandbox = await Sandbox.create({ timeoutMs: 60_000 })
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"
// }
from e2b import Sandbox
 
sandbox = Sandbox.create(timeout=60)
info = sandbox.get_info()
print(info)
# SandboxInfo(sandbox_id='ig6f1yt6idvxkxl562scj-419ff533',
#   template_id='u7nqkmpn3jjf1tvftlsu', name='base', metadata={}, ...)

Shut it down#

kill() stops the sandbox immediately, whatever time is left on the timeout.

await sandbox.kill()
sandbox.kill()

How long can a sandbox run?#

Continuous runtime is capped by plan: up to 1 hour on Hobby and 24 hours on Pro. Pausing and resuming resets that window, and a paused sandbox keeps its full state indefinitely — see Persistence.

Next#

Updated

Was this page helpful?