# Snapshots

A snapshot is a save point that outlives its sandbox. `POST /v1/snapshots` with a `sandbox_id` keeps the sandbox as it is now; add `snapshot_id` to keep one of its save points instead, which also works while the sandbox is paused. The snapshot belongs to your team and stays when the sandbox is deleted.

`POST /v1/sandboxes` with `snapshot_id` starts a new sandbox from it: the same memory, disk and running processes, with its own id, address and hostname. Start as many as you like. The new sandbox has the snapshot's size, so leave `cpus`, `memory_gb` and `disk_gb` out. Its `env` is added to the commands you run in it; processes that were already running keep the environment they had.

```
# Keep the sandbox as it is now. The answer has the snapshot's id (snap_...)
curl -X POST https://api.groundbox.dev/v1/snapshots \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" -H "content-type: application/json" \
  -d '{"sandbox_id": "sbx_...", "label": "deps installed"}'

# A new sandbox from it, also after the first one is deleted
curl -X POST https://api.groundbox.dev/v1/sandboxes \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" -H "content-type: application/json" \
  -d '{"snapshot_id": "snap_..."}'

# The team's snapshots, and deleting one
curl https://api.groundbox.dev/v1/snapshots \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY"
curl -X DELETE https://api.groundbox.dev/v1/snapshots/snap_... \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY"
```

- `GET /v1/snapshots` lists them with the sandbox each was taken of, its size, label and creation time; `?sandbox_id=` narrows it to one sandbox. `DELETE /v1/snapshots/{id}` deletes one.
- Deleting a snapshot does not touch sandboxes already started from it, and deleting a sandbox does not touch its snapshots.
- Storage is $0.05 per GB-month, the same as a paused sandbox, on every plan. A snapshot's `size_bytes` is the memory in use plus what the sandbox added to its disk; the image it started from is not counted. A team keeps up to 50 snapshots and 100 GB together.
- A snapshot that no sandbox was started from for a month is deleted; its `expires_at` says when. Starting a sandbox from it moves that date on.
- `memory` on a snapshot says whether it holds memory and processes. When it does not, or the memory cannot be loaded any more, the sandbox boots from the snapshot's disk: the files are there, the processes are not. The sandbox's `start` is `warm` when memory came back and `cold` when only the disk did.
- A sandbox with volumes or a desktop cannot be started from a snapshot, and a sandbox with volumes cannot be kept as one.

```
import { Groundbox } from "@groundbox/sdk";

const groundbox = new Groundbox();
const snapshot = await groundbox.keep_snapshot({ sandbox_id: "sbx_...", label: "deps installed" });
await groundbox.delete_sandbox("sbx_...");
const sandbox = await groundbox.create_sandbox({ snapshot_id: snapshot.id });
const { data } = await groundbox.list_snapshots();
await groundbox.delete_snapshot(snapshot.id);
// groundbox snapshot keep sbx_...   |   groundbox sandbox create --snapshot snap_...   |   MCP: snapshot (action keep or delete), snapshot_info (action list)
```

From the CLI: `groundbox snapshot keep <sandbox_id>` (the same as `groundbox sandbox snapshot <sandbox_id> --keep`), `groundbox snapshot list`, `groundbox snapshot delete <snap_id>`, and `groundbox sandbox create --snapshot <snap_id>`.
