# Time machine

A running sandbox can keep a timeline of save points: its memory, its disk and every running process, as they were at that moment. Rewind to any of them, or fork one into many copies. After the first, a save point holds only the memory pages and disk blocks changed since the one before, so a minute of history usually costs megabytes, and the sandbox stands still for milliseconds while it is taken (each point says how long, as `pause_ms`). Points every 2 seconds at the most often; the oldest go first past `keep` or your team's storage. They are deleted with the sandbox, unless you keep one as a [snapshot](https://groundbox.dev/docs/sandboxes/snapshots). Save points are on every plan.

```
# A save point every 5 seconds, keeping the newest 30
curl -X POST https://api.groundbox.dev/v1/sandboxes/sbx_.../timeline \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" -H "content-type: application/json" \
  -d '{"interval_s": 5, "keep": 30}'

# One now, with a label; the answer has its id (snap_...) and how long the sandbox stood still
curl -X POST https://api.groundbox.dev/v1/sandboxes/sbx_.../snapshots \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" -H "content-type: application/json" \
  -d '{"label": "before the migration"}'

# Back to it: memory, disk and every process as they were. Same sandbox id.
curl -X POST https://api.groundbox.dev/v1/sandboxes/sbx_.../restore \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" -H "content-type: application/json" \
  -d '{"snapshot_id": "snap_..."}'

# 10 copies of that moment, each with FORK_INDEX in its env (copies count toward your team's sandboxes at once)
curl -X POST https://api.groundbox.dev/v1/sandboxes/sbx_.../fork \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" -H "content-type: application/json" \
  -d '{"count": 10, "snapshot_id": "snap_..."}'
```

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

const sandbox = new Groundbox().sandbox("sbx_...");
await sandbox.timeline.enable({ interval_s: 5 });
const point = await sandbox.snapshot("app loaded");
await sandbox.restore(point.id);
const group = await sandbox.fork(10, { onProgress: (g) => console.log(g.progress) });
// groundbox sandbox fork sbx_... --count 10   |   MCP: snapshot, action save_point, rewind or fork_universes
```

A rewind keeps the sandbox's id: what it did since the point is gone, and open connections to it reconnect (streamed commands pick up where they were). A fork with `count` answers with a fork group at once; `GET /v1/fork-groups/{id}` shows the copies coming up, and `DELETE /v1/fork-groups/{id}` ends them all. The copies share the moment's memory until they write to it, each has its own address, hostname and machine id, and `FORK_INDEX` (0 to count - 1) tells each which one it is, in every command's env and in `/run/groundbox/fork.env`. Up to 50 copies per fork. Copies count toward your team's sandboxes at once (20 once a card is on file, 2 before), so a larger fork needs a higher limit: ask us.

A paused sandbox keeps its save points. Fork it from one with `snapshot_id`; without one it has to be resumed first. To drop a single save point of a running sandbox, call `DELETE /v1/sandboxes/{id}/snapshots/{snapshot_id}`. Every save point is whole on its own, so the ones after it, and sandboxes forked from it, are not touched.
