Skip to main content

Pause and resume

In the cURL example the last answer holds remembered in stdout. A pause answers 204. A resume answers 201 with the sandbox as a create answer: the same sandboxID, the same state it had before the pause, and a new timeout (seconds, as on create). Pausing a paused sandbox, or resuming a running one, answers 409. A command on a paused sandbox answers 412 sandbox_paused: resume it first. POST /sandboxes/{id}/connect returns the sandbox the same way and resumes it if it is paused.

Pause tiers

A pause keeps a sandbox’s state so a resume is transparent: the process, its memory and its open files are where they were. There are three tiers, and the tier decides how much is kept and how long a resume takes. Pick the tier by how long you will be away. A pause with no body is a memory pause; a tier other than these three is refused with 400 invalid_argument.

Timeouts

timeout on create is the number of seconds the sandbox lives, from the start: 1 to 86,400, and 300 when you leave it out (a plan may allow less). While a sandbox is paused no timeout runs.
/timeout sets a new lifetime from now. /refreshes keeps the sandbox alive for at least that many more seconds and never shortens it, so a keep-alive loop can call it freely. Both answer 204. In the SDKs it is sbx.set_timeout(600) and sbx.setTimeout(600_000). A sandbox that reaches its timeout is killed and answers 410 sandbox_timeout.

Pause on timeout instead of kill (auto-sleep)

Create the sandbox with "lifecycle": {"onTimeout": "pause", "autoResume": true} (the E2B SDKs send the same fields) and a sandbox that reaches its timeout is paused instead of killed; with autoResume, the next call to it wakes it. autoResume needs onTimeout: "pause", or the create answers 400. GET /sandboxes/{id} shows the state. An account with snapshots_off_on_stop set gets a kill at the timeout whatever the create asks.

While it runs: processes and the clock keep going

A running sandbox keeps running its processes and its clock from create until its timeout, whether or not a command or a request is in flight: a server or job you started with nohup ... & is still there, and still working, when you come back. The platform puts a running sandbox to sleep only when nothing of yours runs inside it (no process started after the sandbox was created: no server, job or open shell). Such a sandbox costs nothing to keep and wakes in milliseconds on the next command, file call or connection, so there is nothing to notice. To save money on a sandbox that does keep a process running, give it an idle sleep of your own on create: "idleTimeout": 120 (seconds, 0 to 3600; 0 or absent means none). The sandbox then sleeps once nothing has called or connected to it for that long, even if a process is running, and wakes on the next call or connection; while it sleeps the processes and the clock are stopped. A job that must keep running on its own needs no idleTimeout. A cron entry or timer with no process alive between runs is not counted as work: keep a process in the sandbox (a scheduler loop is one).

What is metered

  • A running sandbox is metered per second until it is killed, reaches its timeout or is paused.
  • A paused sandbox is metered at its tier’s rate. A memory pause keeps its memory on the node and still counts against your concurrent sandboxes; a standby or archived sandbox does not, and a slot is free the moment a sandbox is killed or put to standby (see limits).
  • A browser session is metered only while it is awake; a paused or sleeping browser accrues no charge.
  • Billing says what is metered, and GET /v1/run/usage shows your own numbers.
A paused sandbox you forget still counts against your sandboxes held in any state: kill what you no longer need.

Snapshots

A snapshot saves memory and disk under a name; any later sandbox of yours can start from it and begins exactly there. The full set of calls, with listing, deleting and reading files inside a snapshot, is on Snapshots.
The second call answers 201 with a new sandboxID whose /root/state.txt is already there. A name is unique per account (409 when taken). Run sync in the sandbox before you save it when you want its files to be visible without starting it.

Operations