---
title: Checkpoints and rollback
description: Take a named snapshot of a sandbox's disk before a risky step, and roll the sandbox back to it if the step goes wrong.
---

A checkpoint is a named snapshot of a sandbox's disk. Take one before a risky step, such as a migration, an upgrade or an agent's run, and roll the sandbox back to it if the step goes wrong.

```sh
pols checkpoint create web before-migration
pols exec web -- bash -lc 'cd app && make migrate'
pols rollback web before-migration     # if it went wrong
pols checkpoint ls web                 # oldest first
pols checkpoint rm web before-migration
```

## Taking a checkpoint

`pols checkpoint create SANDBOX NAME` (`POST /v1/sandboxes/{sandbox}/checkpoints` with `name`) snapshots the disk at once: the checkpoint exists when the call returns. The name is lowercase letters, digits and dashes, starting with a letter, and unique among the sandbox's checkpoints. Each checkpoint also has an ID, `ckp_...`; either works wherever a checkpoint is named.

- The sandbox may be running, stopped or in [standby](/docs/sandboxes/lifecycle/#standby); one in standby is woken first. A sandbox that is being resized or rolled back cannot take one, and neither can the sandboxes pols runs a [database](/docs/publish/databases/) or a site's server app in.
- A checkpoint holds the disk only, not memory or running processes. A running sandbox's disk is taken as a power cut would leave it: run `sync` first for files that were just written. Databases and other services that write to disk recover from it as they would after a power cut.

## Rolling back

`pols rollback SANDBOX CHECKPOINT` (`POST /v1/sandboxes/{sandbox}/rollback` with `checkpoint`) discards every change to the sandbox's disk since the checkpoint:

- A running sandbox, or one in standby, is shut down, rolled back and booted again, so the processes running in it stop. A stopped sandbox is rolled back and stays stopped.
- The checkpoints taken after it are deleted, and so are the snapshots taken when the sandbox stopped since. The checkpoint itself is kept, so you can roll back to it again.
- The sandbox's [Linux users](/docs/reference/cli/users/) become the ones it had when the checkpoint was taken. A user that a rollback brings back counts as a new user: API keys [limited to a user](/docs/account/key-limits/#keys-limited-to-one-linux-user) that was removed stay ended.

A rollback is asynchronous, like a [resize](/docs/concepts/machine/#resizing): the API answers at once, and the sandbox has `rollback_to` set until it is done. The CLI waits for it (`--no-wait` returns at once, `--wait-timeout` sets how long to wait); over the API, poll `GET /v1/sandboxes/{sandbox}` until `rollback_to` is null again and `status` equals `desired_state`.

A rollback is refused with `409 conflict`:

- while a fork or template made from the sandbox after the checkpoint exists, since its disk is a copy of newer state; delete it first;
- when the sandbox's disk was resized since the checkpoint, as a rollback would shrink it;
- while the sandbox is being created, deleted, resized or rolled back, or a fork or template of it is being copied;
- for the sandboxes pols runs a database or a site's server app in.

If the rollback fails anyway, the sandbox keeps its disk and its checkpoints (less the later ones already deleted) and is started again if it was to run. Its `last_error` and its [timeline](/docs/sandboxes/timeline/) say what happened, and the waits of the CLI, the MCP server and the clients fail.

## Limits and cost

- A sandbox keeps at most 10 checkpoints; another one is refused with `403 quota_exceeded`. Delete old ones with `pols checkpoint rm`.
- A checkpoint's space is what the disk changed since it was taken. It counts as the sandbox's disk and is billed as such.
- Checkpoints are deleted with the sandbox, and forks and templates do not copy them. They are snapshots on the sandbox's own disk, not backups: keep anything you cannot lose outside the sandbox.

## Checkpoints, forks and templates

| Use | When |
| --- | --- |
| A checkpoint | to return the same sandbox to an earlier state |
| A [fork](/docs/sandboxes/forks/) | to try something in a second sandbox while the first one stays as it is |
| A [template](/docs/sandboxes/templates/) | to start many new sandboxes from one prepared disk |

## From agents and code

The [MCP server](/docs/agents/mcp/) has `checkpoint_create`, `checkpoint_list`, `checkpoint_delete` and `sandbox_rollback`, which waits unless `no_wait` is set. The TypeScript and [Python](/docs/agents/python/) clients have `checkpoints.create`, `.list` and `.delete`, and `sandboxes.rollback`; the Python client's `sandboxes.wait_for` raises `PolsError` with code `rollback_failed` when a rollback could not be done.

A key [limited to sandboxes](/docs/account/api-keys/#keys-limited-to-sandboxes) may take checkpoints of its sandboxes and roll them back, unless its [limits](/docs/account/key-limits/) leave out `checkpoint` (`403 key_limit`). A key limited to one Linux user of a sandbox may not roll it back (`403 forbidden`), as a rollback acts on the whole sandbox.
