> ## Documentation Index
> Fetch the complete documentation index at: https://docs.primeintellect.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Checkpoints & Forking

> Save a sandbox's filesystem or memory, restore it, or branch it

A checkpoint saves a sandbox's filesystem so you can start new sandboxes from it later, or fork a running one to branch your work. It captures the sandbox's root filesystem only — data on mounted [volumes](https://docs.primeintellect.ai/sandboxes/volumes.md) is never included. A filesystem checkpoint holds **files only**: processes start fresh and nothing in memory carries over. Other operations also capture memory and running processes:

| Operation | Captures | Creates a sandbox | Source |
| - | - | - | - |
| `checkpoint` / `checkpoint create` | root disk | no | keeps running |
| `snapshot` / `sandbox snapshot` | disk, memory, processes | no | paused, then resumed |
| `fork` | root disk | yes | keeps running |
| `fork --with-memory` | disk, memory, processes | yes | paused, then resumed |
| [`pause`](./pause-resume) | disk, memory, processes | no | stays `PAUSED` until `resume` |

A filesystem checkpoint is usable once it reaches `DURABLE`. From then on it outlives its source sandbox. Checkpoint storage is [billed separately](https://docs.primeintellect.ai/sandboxes/overview.md#pricing).

> [!NOTE]
>
> `snapshot` and `fork --with-memory` need prime 0.23.0 or later, or prime-sandboxes 0.5.14 or later for the SDK.

> [!WARNING]
>
> Keep the source sandbox alive until the checkpoint is `DURABLE`. If it's
> deleted or hits its timeout first, the checkpoint is lost.

## Fork

The quickest way to branch a running sandbox. It checkpoints, waits for `DURABLE`, and starts a new sandbox from it:

```bash theme={null}
prime sandbox fork sbx_123 --name experiment-branch --yes
```

The fork inherits the source's CPU, memory, and timeout unless you pass `--cpu-cores`, `--memory-gb`, or `--timeout-minutes`. Use `--wait-timeout` (seconds) to cap how long it waits for the checkpoint.

`--with-memory` forks the source's memory and running processes too:

```bash CLI theme={null}
prime sandbox fork sbx_123 --with-memory --name experiment-branch --yes
```

```python Python theme={null}
forked = client.fork(sandbox_id, name="experiment-branch", with_memory=True)
client.wait_for_creation(forked.id)
```

The source is paused for the snapshot and resumed asynchronously; check `prime sandbox get sbx_123` before using it again. The fork takes the paused sandbox's shape, environment, and secrets, so `--with-memory` rejects `--cpu-cores` and `--memory-gb`. It also rejects `--volume`: a memory fork continues the paused guest and attaches no volume. GPU sandboxes and sandboxes with volumes cannot be paused, so they cannot be memory-forked.

## Memory snapshots

`snapshot` captures a sandbox's disk, memory, and running processes without creating another sandbox. It pauses the source, waits until the pause checkpoint is restorable and the source is `PAUSED`, then resumes the source. The returned checkpoint restores with `--memory`.

```bash CLI theme={null}
# Prints the checkpoint ID; the source resumes asynchronously
prime sandbox snapshot sbx_123

# Restore the snapshot into a new sandbox that continues the paused processes
prime sandbox checkpoint restore <checkpoint-id> --memory --yes
```

```python Python theme={null}
snapshot = client.snapshot(sandbox_id)

restored = client.create(
    CreateSandboxRequest(
        name="restored-sandbox",
        checkpoint_id=snapshot.id,
        restore_memory=True,
    )
)
client.wait_for_creation(restored.id)
```

`--wait-timeout` (CLI) or `timeout_seconds` (SDK, default 300) bounds only the pause-ready wait. The source's resume is asynchronous, and the returned checkpoint is not necessarily `DURABLE`: it shows `FROZEN` or `DURABLE` when the source is `PAUSED`. `prime sandbox checkpoint get <checkpoint-id>` shows its state and size; it does not report whether memory was stored. `wait_for_checkpoint` waits for disk durability, not proof that the memory snapshot was stored.

A pause checkpoint whose memory has not yet been stored can be memory-restored only on the pausing node, while the source exists; a disk-only restore needs `DURABLE`. `DURABLE` stores the checkpoint's disk off the pausing node, so a disk restore survives source deletion, but it does not guarantee the memory was stored: memory that misses the platform's pause window (currently 6 hours) is dropped. A pause checkpoint has no TTL, but its disk must become `DURABLE` within about 6 hours of the pause, and its memory within about 6 hours after that. Paused time counts against the source's timeout. GPU sandboxes and sandboxes with volumes cannot be paused, so they cannot be snapshotted.

If the response is lost and the source shows `PAUSED`, continue it with `prime sandbox resume sbx_123`.

## Restore memory

`checkpoint restore <checkpoint-id> --memory` (CLI) or `create(..., restore_memory=True)` (SDK) creates a new sandbox that continues the paused sandbox's memory, processes, environment, and secrets. It never restores into the source, and the same pause checkpoint can be restored more than once.

A memory restore uses the paused sandbox's shape: leave out `--cpu-cores` and `--memory-gb`. It cannot attach [volumes](https://docs.primeintellect.ai/sandboxes/volumes.md), and [gang members](https://docs.primeintellect.ai/sandboxes/lifecycle.md#gangs) cannot restore memory. The platform needs the source sandbox record, which it keeps for at least 7 days after termination; once that record is removed, only a disk restore is possible. Set the new sandbox's lifetime explicitly: `--timeout-minutes` (CLI) and `timeout_minutes` (SDK) default to 60 even for a memory restore.

A restore copies userspace random state and any keys or tokens already in the guest's memory. Rekey or regenerate them in the restored workload.

## Checkpoint and restore

These examples restore a filesystem checkpoint's disk; processes start fresh. To continue a paused sandbox's memory and processes, use `--memory` as described above.

```bash CLI theme={null}
# 1. Create a checkpoint (prints its ID)
prime sandbox checkpoint create sbx_123

# 2. Poll until its state is DURABLE
prime sandbox checkpoint list sbx_123 --checkpoint-id <checkpoint-id>

# 3. Restore into a new sandbox
prime sandbox checkpoint restore <checkpoint-id> --name restored-workspace --yes
```

```python Python theme={null}
checkpoint = client.checkpoint(sandbox_id)
client.wait_for_checkpoint(checkpoint.id, timeout_seconds=300)

restored = client.create(
    CreateSandboxRequest(name="restored-workspace", checkpoint_id=checkpoint.id)
)
client.wait_for_creation(restored.id)
```

The image and disk size come from the checkpoint, so leave out `docker_image` and `disk_size_gb` in the SDK. Everything else (resources, env vars, timeouts) works as usual; the CLI `restore` accepts `--cpu-cores`, `--memory-gb`, `--timeout-minutes`, and `--team-id`.

`wait_for_checkpoint` returns once the checkpoint is `DURABLE`. It raises `RuntimeError` if the checkpoint fails and `TimeoutError` if the wait runs out. A timeout doesn't mean the checkpoint failed, so check it with `get_checkpoint` before deleting the source sandbox. `list_checkpoints(sandbox_id)` lists a sandbox's checkpoints.
