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

# Snapshots

> Save a running sandbox's memory and disk under a name and start any number of sandboxes from it.

Any sandbox of your account can be started from that name, and each one begins exactly where the saved sandbox was: files,
processes and memory included. To keep one sandbox for yourself, see [Timeouts, pause and resume](https://docs.styne.ai/pause-tiers.md).

## Save a sandbox

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/sandboxes/$SANDBOX_ID/snapshots \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"name": "golden-1"}'
```

The answer is `{"snapshotID", "names", "name", "sandboxID", "templateID", "created"}`. `name` is optional; without one the
snapshot's id is its name. A name is 1 to 128 characters of letters, digits, `.`, `_` and `-`, starts with a letter or a
digit, and is unique in your account: saving a name you already have answers 409. Other accounts never see your names.

## Start sandboxes from a snapshot

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/sandboxes \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"snapshot": "golden-1", "timeout": 300}'
```

`snapshot` replaces `templateID`; every other field of a create works as usual. The sandbox is placed on the node that
holds the snapshot, so a create from a name waits for capacity on that node only. A name you do not have answers 404, and
so does a name you deleted.

## List, read and delete

* `GET /snapshots` lists your saved snapshots, newest first.
* `GET /sandboxes/{id}/snapshots` lists the snapshots taken of one sandbox; the sandbox may be gone.
* `GET /snapshots/{name}` reads one.
* `DELETE /snapshots/{name}` removes the files and then the name (204). It answers 503 when the node holding the snapshot
  does not answer, and leaves the name in place so the delete can be repeated.

Sandboxes already started from a snapshot are not affected by deleting it.

`DELETE /snapshots` removes every saved snapshot of your account at once and answers `{"deleted": 3, "failed": 0}`.
A snapshot whose node does not answer stays listed and is counted in `failed` (the status is then 503), so the call can
be repeated until `failed` is 0.

## Look inside a snapshot

You can read the files of a saved snapshot without starting it; the sandbox it came from can be stopped or gone.

```bash theme={"theme":"css-variables"}
curl -sS "https://api.styne.ai/snapshots/golden-1/tree?path=/home/user" \
  -H "Authorization: Bearer $STYNE_API_KEY"
curl -sS "https://api.styne.ai/snapshots/golden-1/files?path=/home/user/note.txt" \
  -H "Authorization: Bearer $STYNE_API_KEY" -o note.txt
curl -sS "https://api.styne.ai/snapshots/golden-1/archive?path=/home/user" \
  -H "Authorization: Bearer $STYNE_API_KEY" -o user.tar
```

* `tree` answers `[{"path", "size", "dir"}]` for the path and everything below it, sorted by path (the whole disk when
  `path` is empty; at most 20,000 entries).
* `files` returns the bytes of one regular file, at most 32 MiB.
* `archive` returns a tar of a file or a folder, at most 32 MiB of file data in total, with names relative to the parent
  of the path.
* A path that does not exist answers 404, a `..` in a path 400, a result over the limits 413. A snapshot of a
  template that keeps its files in memory (the `code` template) has no disk to browse and answers 409; create a sandbox
  from it to read its files.

What you see is the sandbox's writable disk as it was at the snapshot. Data a program had only in memory, or had not yet
flushed to the disk, is part of a restored sandbox but not of this view; run `sync` in the sandbox before you save it
when you need a file to show up here. Symbolic links and special files are listed but not downloaded.

## Operations

| Method | Path | What it does |
| - | - | - |
| `POST` | `/sandboxes/{id}/snapshots` | Save a sandbox as a named snapshot |
| `GET` | `/sandboxes/{id}/snapshots` | List the snapshots taken of one sandbox |
| `GET` | `/snapshots` | List the account's saved snapshots |
| `GET` | `/snapshots/{name}` | Read one saved snapshot |
| `DELETE` | `/snapshots/{name}` | Delete a saved snapshot |
| `DELETE` | `/snapshots` | Delete every saved snapshot of the account |
| `GET` | `/snapshots/{name}/tree` | List the files inside a saved snapshot |
| `GET` | `/snapshots/{name}/files` | Download one file from a saved snapshot |
| `GET` | `/snapshots/{name}/archive` | Download a file or folder of a saved snapshot as a tar |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.