# Persistence & snapshots

Pause a sandbox to keep its disk and memory, resume it later exactly where it was, or take a snapshot to start new sandboxes from the same state.

![A snapshot copies the sandbox's disk and memory into storage as one piece. Any number of new sandboxes can start from it, each one an exact copy.](/illos/backups.svg)

## Pause and resume

Pausing saves the whole sandbox, files and running processes together, and stops the VM. Resuming brings it back as it was, with the same id, in about two seconds.

```ts TypeScript
await sandbox.pause();
// later, from any process
const again = await kestrel.sandboxes.resume("sbx_41c9");
```

```python Python
sandbox.pause()
# later, from any process
again = kestrel.sandboxes.resume("sbx_41c9")
```

A paused sandbox costs storage only, and its timeout starts again from zero when it resumes.

## Snapshots

A snapshot is a saved copy you can start from as many times as you like. Use one when every run needs the same slow setup, like a seeded database or a warm build cache.

```ts TypeScript {2,5}
// set up once
const snap = await sandbox.snapshot({ name: "web-app-seeded" });

// start every run from it
await kestrel.runs.create({ repo: "acme/web-app", task: "Add an index to orders", from: snap.name });
```

```python Python {2,5}
# set up once
snap = sandbox.snapshot(name="web-app-seeded")

# start every run from it
kestrel.runs.create(repo="acme/web-app", task="Add an index to orders", from_=snap.name)
```

| | Pause | Snapshot |
|---|---|---|
| Keeps running processes | Yes | No, files only |
| Same sandbox id afterwards | Yes | No, a new sandbox each time |
| Start more than one copy | No | Yes |
| Kept for | Until you kill it | 30 days after its last use |

> [!TIP]
> A snapshot is taken from the repo at its current commit. When `main` moves on, Kestrel pulls the new commits into each sandbox it starts from the snapshot, so you don't have to retake it after every merge.
