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

# Snapshots

> Set a sandbox up once (dependencies installed, data loaded, servers running), take a snapshot of its whole state with its memory, and start as many sandboxes from it as you need, each already running and ready to work.

Before a new sandbox can do real work, it usually needs the same setup: clone the repository, install
dependencies, download a model, start a server. If every sandbox does that from scratch, each one spends **minutes
of waiting, and of paid compute, before any real work starts**.

A **snapshot** removes that wait. You prepare one sandbox exactly the way you want it, take a snapshot of it, and
then start new sandboxes from the snapshot. A snapshot keeps the sandbox's **whole state: its files, its running
programs and their memory**. **Each new sandbox starts exactly where the snapshot was: the files are in place, the
programs are running, and the data is already in memory.** The setup happens once, and every sandbox after that is
ready to work immediately.

Here is the difference:

| Without a snapshot | With a snapshot |
| - | - |
| Create → clone → install → start the server → **work** | Create from the snapshot → **work** |
| Setup repeated for every user and every task | Setup done once |
| Each sandbox may install slightly different versions | Every sandbox identical |

## Take a snapshot

In this example, the snapshot is of a small app whose dependencies are installed and whose server is **already
running, with data loaded into memory**.

**1. Prepare a sandbox**

Start a sandbox and do all the slow work you want to save your future sandboxes from: install, build, load data,
start servers.

```bash title="CLI" run theme={null}
BASE=$(fibre create --port 3000 --lifetime 30m --label docs=snapshots --json | jq -r .id)

fibre exec "$BASE" -i -- sh -c 'mkdir -p /app && cat > /app/server.js' <<'JS'
const http = require("http");
const { z } = require("zod");                                          // a dependency, installed below
const bootedAt = new Date().toISOString();
const catalog = Array.from({ length: 100000 }, (_, i) => ({ id: i, price: (i % 97) + 0.99 }));   // warm data
http.createServer((req, res) => {
  res.writeHead(200, { "content-type": "application/json" });
  res.end(JSON.stringify({ bootedAt, items: catalog.length, zod: typeof z.string }));
}).listen(3000);
JS

fibre exec "$BASE" -- 'cd /app && npm init -y > /dev/null && npm install --silent zod'
fibre exec "$BASE" --cwd /app --detach --keep -- node /app/server.js
fibre exec "$BASE" --timeout 60 -- 'until curl -sf -o /dev/null localhost:3000; do sleep 1; done'
```

```typescript title="TypeScript" run theme={null}
import { Sandbox, Snapshot } from "@fibre-dev/sdk";

const base = await Sandbox.create({ exposedPort: 3000, lifetime: 1800, labels: { docs: "snapshots" } });

await base.files.write("/app/server.js", `
const http = require("http");
const { z } = require("zod");                                          // a dependency, installed below
const bootedAt = new Date().toISOString();
const catalog = Array.from({ length: 100000 }, (_, i) => ({ id: i, price: (i % 97) + 0.99 }));   // warm data
http.createServer((req, res) => {
  res.writeHead(200, { "content-type": "application/json" });
  res.end(JSON.stringify({ bootedAt, items: catalog.length, zod: typeof z.string }));
}).listen(3000);
`);

await base.run("cd /app && npm init -y > /dev/null && npm install --silent zod", { timeout: 300 });
await base.spawn(["node", "/app/server.js"], { cwd: "/app", keep: true });
await base.run("until curl -sf -o /dev/null localhost:3000; do sleep 1; done", { timeout: 60 });
```

```python title="Python" run theme={null}
from fibre import Sandbox, Snapshot

base = Sandbox.create(exposed_port=3000, lifetime=1800, labels={"docs": "snapshots"})

base.files.write("/app/server.js", """
const http = require("http");
const { z } = require("zod");                                          // a dependency, installed below
const bootedAt = new Date().toISOString();
const catalog = Array.from({ length: 100000 }, (_, i) => ({ id: i, price: (i % 97) + 0.99 }));   // warm data
http.createServer((req, res) => {
  res.writeHead(200, { "content-type": "application/json" });
  res.end(JSON.stringify({ bootedAt, items: catalog.length, zod: typeof z.string }));
}).listen(3000);
""")

base.run("cd /app && npm init -y > /dev/null && npm install --silent zod", timeout=300)
base.spawn(["node", "/app/server.js"], cwd="/app", keep=True)
base.run("until curl -sf -o /dev/null localhost:3000; do sleep 1; done", timeout=60)
```

```bash title="curl" run capture=BASE=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"exposed_port": 3000, "lifetime_sec": 1800, "labels": {"docs": "snapshots"}}'
```

```bash title="curl: install and start the app" run theme={null}
cat <<'EOF' | curl -sS -o /dev/null -X PUT "$FIBRE_API_URL/v1/sandboxes/$BASE/files/content?path=/app/server.js" \
  -H "Authorization: Bearer $FIBRE_API_KEY" --data-binary @-
const http = require("http");
const { z } = require("zod");
const bootedAt = new Date().toISOString();
const catalog = Array.from({ length: 100000 }, (_, i) => ({ id: i, price: (i % 97) + 0.99 }));
http.createServer((req, res) => {
  res.writeHead(200, { "content-type": "application/json" });
  res.end(JSON.stringify({ bootedAt, items: catalog.length, zod: typeof z.string }));
}).listen(3000);
EOF

INSTALL=$(curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$BASE/commands" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "cd /app && npm init -y > /dev/null && npm install --silent zod"]}' | jq -r .command_id)
curl -sSN "$FIBRE_API_URL/v1/sandboxes/$BASE/commands/$INSTALL/logs?follow=1" \
  -H "Authorization: Bearer $FIBRE_API_KEY" > /dev/null

curl -sS -o /dev/null -X POST "$FIBRE_API_URL/v1/sandboxes/$BASE/commands" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["node", "/app/server.js"], "cwd": "/app", "keep": true}'

curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$BASE/exec" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "until curl -sf localhost:3000; do sleep 1; done"]}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "exit_code": 0,
>   "stdout": "…"
> }
> ```

**2. Take the snapshot**

```bash title="CLI" run theme={null}
fibre snapshot create docs-node-app --from "$BASE"
```

```typescript title="TypeScript" run theme={null}
const snapshot = await base.snapshot({ name: "docs-node-app" });
console.log(snapshot.name, snapshot.sizeBytes, snapshot.monthlyCostUsd); // docs-node-app 4… 0.0…
```

```python title="Python" run theme={null}
snapshot = base.snapshot(name="docs-node-app")
print(snapshot.name, snapshot.size_bytes, snapshot.monthly_cost_usd)  # docs-node-app 4… 0.0…
```

```bash title="curl" run theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/snapshots" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d "{\"name\": \"docs-node-app\", \"from\": \"$BASE\"}"
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "name": "docs-node-app",
>   "from": "…",
>   "image": "…",
>   "cpu_cores": "…",
>   "memory_mb": "…",
>   "exposed_port": 3000,
>   "size_bytes": "…",
>   "monthly_cost_usd": "…",
>   "created_at": "…"
> }
> ```

Taking a snapshot does not stop the sandbox: **it keeps running**. Snapshot names can use lowercase letters, digits
and `-`.

**3. Start sandboxes from it**

Now create sandboxes from the snapshot. Each one is a new, separate sandbox with its own ID, address and files,
but it **starts exactly as the snapshot was**. This example creates three at once, one for each of three users:

```bash title="CLI" run theme={null}
COPIES=""
for user in alice bob carol; do
  COPIES="$COPIES $(fibre create --snapshot docs-node-app --lifetime 15m --label docs=snapshots --label user=$user --json | jq -r .id)"
done

for copy in $COPIES; do
  fibre exec "$copy" -- curl -s localhost:3000; echo   # {"bootedAt":"…","items":100000,"zod":"function"}
done
```

```typescript title="TypeScript" run theme={null}
const copies = await Promise.all(
  ["alice", "bob", "carol"].map((user) =>
    Sandbox.create({ snapshot: "docs-node-app", lifetime: 900, labels: { docs: "snapshots", user } })),
);

for (const copy of copies) {
  const answer = JSON.parse((await copy.run("curl -s localhost:3000")).stdout);
  console.log(copy.labels.user, answer); // alice { bootedAt: '…', items: 100000, zod: 'function' }
}
```

```python title="Python" run theme={null}
import json
from concurrent.futures import ThreadPoolExecutor

with ThreadPoolExecutor() as pool:
    copies = list(pool.map(
        lambda user: Sandbox.create(snapshot="docs-node-app", lifetime=900, labels={"docs": "snapshots", "user": user}),
        ["alice", "bob", "carol"],
    ))

for copy in copies:
    answer = json.loads(copy.run("curl -s localhost:3000").stdout)
    print(copy.labels["user"], answer)  # alice {'bootedAt': '…', 'items': 100000, 'zod': 'function'}
```

```bash title="curl" run capture=COPY=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"snapshot": "docs-node-app", "lifetime_sec": 900, "labels": {"docs": "snapshots", "user": "alice"}}'
```

```bash title="curl: the server is already up" run theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$COPY/exec" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["curl", "-s", "localhost:3000"]}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "exit_code": 0,
>   "stdout": "…"
> }
> ```
>
> `stdout` holds the server's answer, which looks like this:
>
> ```json title="stdout" theme={null}
> {
>   "bootedAt": "2026-11-21T01:52:10.418Z",
>   "items": 100000,
>   "zod": "function"
> }
> ```

**Every new sandbox reports the same `bootedAt` time, which is the moment the snapshot's server started.** None of
them ran `npm install`, started the server or built the catalog. They all began with that work already done.

## What a new sandbox gets

A sandbox created from a snapshot shares some things with the snapshot and has others of its own:

| | From the snapshot | Its own |
| - | - | - |
| Files, installed packages | ✓ (as its own copy: changes in one sandbox never affect another) | |
| Running programs and their memory | ✓ | |
| Image, size, runtime, environment, exposed port | ✓ | |
| ID, `url`, labels, lifetime, idle timeout | | ✓ |

> [!NOTE]
>
> **When you create a sandbox from a snapshot, you can only set `lifetime_sec`, `idle_timeout_sec` and `labels`.**
> Everything else comes from the snapshot. If you send another setting, the request is refused with
> `400 snapshot_fields_fixed`.

## Where snapshots fit

Snapshots help wherever many sandboxes need the same starting point:

* **A workspace per user.** Keep one snapshot with your stack. Each user's sandbox is created from it, and is
  ready the moment they sign in.
* **Agents in parallel.** Keep one snapshot with the repository cloned and dependencies installed, and create one
  sandbox per task.
* **Evals and reinforcement learning.** Every episode gets a fresh, identical environment, with nothing left over
  from the previous one.
* **Code interpreters.** Keep a Python process with pandas and your libraries already imported, so the user's
  first piece of code runs at once.

> [!TIP]
>
> **Put the slow, shared work in the snapshot, and the per-user work in each sandbox.** Install and load before you
> take the snapshot, then add each user's own data after their sandbox starts. When your dependencies change, take a
> new snapshot.

## List and delete

You can list your snapshots, with what each one stores, and delete the ones you no longer need:

```bash title="CLI" run theme={null}
fibre snapshot list

fibre delete $COPIES
fibre snapshot delete docs-node-app   # after the sandboxes started from it
fibre delete "$BASE"
```

```typescript title="TypeScript" run theme={null}
for (const s of await Snapshot.list()) console.log(s.name, s.sizeBytes, s.monthlyCostUsd);

for (const copy of copies) await copy.delete();
await (await Snapshot.get("docs-node-app")).delete();   // after the sandboxes started from it
await base.delete();
```

```python title="Python" run theme={null}
for s in Snapshot.list():
    print(s.name, s.size_bytes, s.monthly_cost_usd)

for copy in copies:
    copy.delete()
Snapshot.get("docs-node-app").delete()  # after the sandboxes started from it
base.delete()
```

```bash title="curl" run theme={null}
curl -sS "$FIBRE_API_URL/v1/snapshots" -H "Authorization: Bearer $FIBRE_API_KEY"
echo
curl -sS -X DELETE "$FIBRE_API_URL/v1/sandboxes/$COPY" -H "Authorization: Bearer $FIBRE_API_KEY"
curl -sS -X DELETE "$FIBRE_API_URL/v1/snapshots/docs-node-app" -H "Authorization: Bearer $FIBRE_API_KEY"
curl -sS -X DELETE "$FIBRE_API_URL/v1/sandboxes/$BASE" -H "Authorization: Bearer $FIBRE_API_KEY"
```

* **Deleting the sandbox you took a snapshot of does not delete the snapshot.** The snapshot is kept separately.
* **A snapshot cannot be deleted while sandboxes created from it still exist.** Delete those sandboxes first.
* **A snapshot is kept until you delete it.** It does not expire.

## What it costs

A snapshot is stored, so **it counts towards your account's storage** for as long as you keep it. Every account
includes **20 GB** of storage, shared by your snapshots and your sleeping sandboxes, and storage beyond that costs
**\$0.10 per GB per month**. See [pricing](https://docs.fibre.dev/get-started/pricing.md#storage).

Each snapshot tells you what it stores and what that size costs:

* **`size_bytes`**: how much it stores, files, memory and running programs together.
* **`monthly_cost_usd`**: what that size costs a month at the storage price. Your included 20 GB come first, so
  while your storage stays under it, you pay nothing for it.

Delete the snapshots you no longer need to stop paying for them.

## Good to know

A few more details:

| | |
| - | - |
| Runtimes | Both. On `vm`, wait until the source's commands have ended before saving |
| Runtime of a new sandbox | The snapshot's |
| Storage | Counts towards your account's storage until deleted ([what it costs](#what-it-costs)) |
| Names | Lowercase letters, digits and `-`, up to 100 characters, unique in your account |

## Errors

These are the errors you may see when working with snapshots. A snapshot of a `vm` sandbox is also refused while a
command is still running in it, so wait for its commands to finish first.

| Status | Code | When |
| - | - | - |
| 400 | `snapshot_fields_fixed` | A new sandbox was given a field it takes from the snapshot |
| 404 | `snapshot_not_found` | No snapshot with that name |
| 409 | `snapshot_exists` | A snapshot with that name already exists |
| 409 | `snapshot_in_use` | Deleting a snapshot while sandboxes created from it still exist |

## Related

> [card] [Images and builds](https://docs.fibre.dev/setup/images.md)
>
> Where a sandbox starts on day one: a registry image or one built from a Dockerfile.

> [card] [Sleep and wake](https://docs.fibre.dev/sandboxes/sleep-and-wake.md)
>
> The same memory-keeping that makes snapshots work.


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