# Checkpoints

Every command, file write and process start ends in a checkpoint: the sandbox's state right after it. You can roll back to any checkpoint of a sandbox, or fork any checkpoint into new sandboxes.

## What a checkpoint holds

| Kind | When | Holds |
| --- | --- | --- |
| `files` | Nothing is running in the background | The sandbox's disk: `/workspace`, `/tmp` and home |
| `full` | A process is running in the background | The disk and the machine's memory, so running processes come back running |

Files checkpoints are copy-on-write copies of the disk, ready before the command's response is sent. Memory checkpoints store only the memory that changed since the sandbox's previous one (about 2 MiB a time) and are written just after the response; the sandbox's next call waits for them.

## List

```sh
GET /v1/sandboxes/:id/checkpoints?limit=50&before=<seq>
```

Newest first, each with its `seq`, `kind`, `trigger` (`create`, `command`, `file`, `process`, `hibernate`, `fork`), the command and its exit code.

## Roll back

```sh
POST /v1/sandboxes/:id/rollback   {"checkpointId": "ck_..."}
```

The sandbox goes back to that checkpoint; later commands branch from it, and the checkpoints after it stay in the list.

## Fork

```sh
POST /v1/checkpoints/:id/fork   {"count": 2}
```

Up to 8 new sandboxes, each starting from the checkpoint. Use it to try alternatives in parallel, or to keep a known-good state.

## Keep

- Checkpoints are kept for 7 days; a sandbox's newest one is kept as long as the sandbox exists.
- The newest 20 memory checkpoints of each sandbox keep their memory; older ones keep their files.
- `POST /v1/checkpoints/:id/pin` keeps one past retention (pinned storage is billed per GB-month after the beta).
- An idle sandbox's newest checkpoint is copied off the host, so it survives the loss of a machine.
