# Pause, resume and snapshots Set the lifetime, pause, resume, kill and snapshot a sandbox. ## Sandbox states | State | What it means | Billed | |---|---|---| | Running | Commands, files and ports work | Yes, per second | | Paused | Memory and files saved | No, for up to 72 hours | | Ended | Killed or timed out. Memory and files deleted. | No | Read the state with `get_info()` / `getInfo()` or `fdtn ls -s running,paused`. ## Lifetime At the end of its lifetime, the sandbox is killed. | Default | 300 s (5 minutes) | |---|---| | Maximum | 24 hours | | CLI minimum | 30 s | | Units | Python: seconds. TypeScript: ms. | Each `fdtn` command that uses a sandbox makes its time left at least 5 minutes. The SDKs do not. Python: ```python sbx = Sandbox.create("base", timeout=3600) # 1 hour ``` TypeScript: ```typescript const sbx = await Sandbox.create('base', { timeoutMs: 3_600_000 }) // 1 hour ``` CLI: ```bash $ fdtn create base -d --timeout 3600 ``` Lifetime is not `request_timeout`, the SDK API wait. ### Change the time left The new value counts from now, up to 24 hours. Python: ```python sbx.set_timeout(600) # 10 more minutes from now info = sbx.get_info() print(info.state, info.end_at) ``` TypeScript: ```typescript await sbx.setTimeout(600_000) // 10 more minutes from now const info = await sbx.getInfo() console.log(info.state, info.endAt) ``` CLI: ```bash $ fdtn sandbox timeout 600 $ fdtn sandbox info ``` ### Pause at the end Set `lifecycle={"on_timeout": "pause"}` (Python), `lifecycle: { onTimeout: 'pause' }` (TypeScript) or `--lifecycle.ontimeout pause` (CLI). ### Terminal sessions An open terminal from `fdtn create` or `fdtn connect` keeps the sandbox running. When you leave `fdtn create`: - By default, the CLI kills the sandbox. - With `--timeout `, it runs that long. - With `--lifecycle.ontimeout pause` and no `--timeout`, it pauses. ## Pause A pause saves memory, files and running programs, and stops billing. Python: ```python sbx.pause() # True when paused, False when it was paused already sandbox_id = sbx.sandbox_id # keep the ID to resume later ``` TypeScript: ```typescript await sbx.pause() // true when paused, false when it was paused already const sandboxId = sbx.sandboxId // keep the ID to resume later ``` CLI: ```bash $ fdtn pause ``` - A paused sandbox is kept 72 hours after its last pause, free. - Paused sandboxes and snapshots hold up to 100 GiB of memory per workspace. [Limits](https://fdtn.dev/docs/limits.md#paused) - For a group, use `fdtn pause --metadata run=eval-1`. ## Resume A connect resumes a paused sandbox, or attaches to a running one. Python: ```python sbx = Sandbox.connect(sandbox_id, timeout=600) # resume, then 10 minutes of lifetime print(sbx.commands.run("cat /tmp/state.txt").stdout) ``` TypeScript: ```typescript const sbx = await Sandbox.connect(sandboxId, { timeoutMs: 600_000 }) console.log((await sbx.commands.run('cat /tmp/state.txt')).stdout) ``` CLI: ```bash $ fdtn resume # resume only $ fdtn connect # resume and open a terminal ``` A resume sets a new lifetime: 5 minutes for the CLI, or the `timeout` you give. On a running sandbox, a longer `timeout` extends it; a shorter one does nothing. `fdtn cp`, `each` and `collect` also resume. A resume does not wait in the queue. If it cannot start, it fails at once with `429`. [Limits](https://fdtn.dev/docs/limits.md) ## Kill A kill ends the sandbox and deletes its memory and files. Call `kill()` in a `finally` block. Python: ```python sbx.kill() # this sandbox Sandbox.kill(sandbox_id) # any sandbox, by ID ``` TypeScript: ```typescript await sbx.kill() // this sandbox await Sandbox.kill(sandboxId) // any sandbox, by ID ``` CLI: ```bash $ fdtn kill # one or more IDs $ fdtn kill --all -m run=eval-1 # only this group ``` `--all` kills every running sandbox. Add `-s running,paused` or `-m` to change the set. ## At the spending limit Running sandboxes pause, so you lose no work. Raise the limit on the Billing page, then resume. [Spending limits](https://fdtn.dev/docs/limits.md#spending) ## Snapshots A snapshot saves memory and files now, for example after a long install. New sandboxes start from it. Python: ```python sbx.create_snapshot(name="ready") # later: start a new sandbox from the snapshot name copy = Sandbox.create("ready") ``` TypeScript: ```typescript await sbx.createSnapshot({ name: 'ready' }) // later: start a new sandbox from the snapshot name const copy = await Sandbox.create('ready') ``` CLI: ```bash $ fdtn snapshot create --name ready $ fdtn create ready -d ``` - Always give a name. You start from it and delete by it. - `claude` and `--trusted` sandboxes cannot make a snapshot (`400 trusted_copy_not_supported`). - If a create from a new snapshot gets `404`, try again after some seconds. - Delete: `fdtn snapshot delete `. - A snapshot counts toward the 100 GiB limit and the template count. It outlives the source sandbox. ## Next - [**Limits and billing**: Queue and spending limits.](https://fdtn.dev/docs/limits.md) - [**Webhooks**: Get a call on state changes.](https://fdtn.dev/docs/webhooks.md) Source: https://fdtn.dev/docs/lifecycle/