> ## 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.

# Create and configure

> Start a sandbox for a user, a task or a conversation: pick its size, image and environment, tag it so you can find it again, retry safely, update it and delete it.

A sandbox is **one isolated Linux machine for one job**: a user's workspace, an agent's task, a conversation, a
test run. You create it when the job starts, tag it with your own IDs, and delete it when the job is done. In
between, it sleeps by itself whenever nothing is happening, so **you can keep thousands around and pay only for the
ones doing work**.

This page follows a sandbox through that life: how to create one, how to find it again later, what you can change
while it runs, how to retry safely, and how to delete it.

## Create one

The simplest sandbox needs no options at all. You get Fibre's default image (Linux with a shell, Python, Node, git
and a browser), ready for you to run commands in:

```bash title="CLI" run theme={null}
FIRST=$(fibre create --json | jq -r .id)
fibre get "$FIRST"   # sbx-… running https://sbx-….fibre.run
fibre delete "$FIRST"
```

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

const first = await Sandbox.create();
console.log(first.id, first.status, first.url); // sbx-… running https://sbx-….fibre.run
await first.delete();
```

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

first = Sandbox.create()
print(first.id, first.status, first.url)  # sbx-… running https://sbx-….fibre.run
first.delete()
```

```bash title="curl" run capture=FIRST=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" -d '{}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "id": "…",
>   "status": "running",
>   "runtime": "standard",
>   "runtime_reason": "default",
>   "idle_timeout_sec": 300,
>   "ready": "process",
>   "labels": {},
>   "created_at": "…",
>   "expires_at": "…",
>   "hostname": "…",
>   "url": "…"
> }
> ```

```bash title="curl: delete it" run theme={null}
curl -sS -X DELETE "$FIBRE_API_URL/v1/sandboxes/$FIRST" -H "Authorization: Bearer $FIBRE_API_KEY"
```

**The call waits until the sandbox is running, and then answers.** You do not need to check back to see whether it
has started. Keep the `id` from the answer, because every other call refers to the sandbox by it.

## A sandbox for one user's task

In a real app you usually set a few things when you create a sandbox:

* **Its size**, so it has enough CPU and memory for the work.
* **Environment variables**, so the code inside knows its context.
* **Labels that tie it to your own records**, such as the user and the task, so you can find it again later.
* **When it should sleep, and when it should be deleted.**

Here is a workspace for user 42, who is working on a task called `fix-login`:

```bash title="CLI" run theme={null}
SBX=$(fibre create \
  --size small \
  --env APP_ENV=preview --env USER_ID=42 \
  --label user=42 --label task=fix-login \
  --idle-timeout 2m \
  --lifetime 1h \
  --json | jq -r .id)

fibre exec "$SBX" -- 'echo "$APP_ENV for user $USER_ID"'   # preview for user 42
```

```typescript title="TypeScript" run theme={null}
const sbx = await Sandbox.create({
  size: "small",                                  // 2 vCPU, 4 GB: enough for most agents
  env: { APP_ENV: "preview", USER_ID: "42" },     // visible to every command inside
  labels: { user: "42", task: "fix-login" },      // yours, to find it again
  idleTimeout: 120,                               // sleep after 2 quiet minutes
  lifetime: 3600,                                 // delete after an hour unless extended
});

const who = await sbx.run('echo "$APP_ENV for user $USER_ID"');
console.log(who.stdout); // preview for user 42
```

```python title="Python" run theme={null}
sbx = Sandbox.create(
    size="small",  # 2 vCPU, 4 GB: enough for most agents
    env={"APP_ENV": "preview", "USER_ID": "42"},  # visible to every command inside
    labels={"user": "42", "task": "fix-login"},  # yours, to find it again
    idle_timeout=120,  # sleep after 2 quiet minutes
    lifetime=3600,  # delete after an hour unless extended
)

who = sbx.run('echo "$APP_ENV for user $USER_ID"')
print(who.stdout)  # preview for user 42
```

```bash title="curl" run capture=SBX=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "size": "small",
    "env_vars": {"APP_ENV": "preview", "USER_ID": "42"},
    "labels": {"user": "42", "task": "fix-login"},
    "idle_timeout_sec": 120,
    "lifetime_sec": 3600
  }'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "id": "…",
>   "status": "running",
>   "image": "…",
>   "cpu_cores": 2,
>   "memory_mb": 4096,
>   "disk_gb": 10,
>   "runtime": "standard",
>   "runtime_reason": "default",
>   "init": null,
>   "created_at": "…",
>   "expires_at": "…",
>   "idle_timeout_sec": 120,
>   "ready": "process",
>   "network": null,
>   "labels": {
>     "user": "42",
>     "task": "fix-login"
>   },
>   "hostname": "…",
>   "url": "…"
> }
> ```

## Every option

Every option is optional: leave any of them out to get the default. Where the SDKs use a different name,
it is shown in brackets.

| Option | Default | What it does |
| - | - | - |
| `image` | Fibre's default image | The filesystem it starts from: a public image (`python:3.12-slim`), or one you [built](https://docs.fibre.dev/setup/images.md) |
| `size` | `small` | `xsmall`, `small`, `medium`, `large` or `xlarge`. See [pricing](https://docs.fibre.dev/get-started/pricing.md#sizes-and-prices) |
| `cpu_cores`, `memory_mb` | | An exact amount instead of a size: 0.25 to 16 cores, 256 MB to 32 GB. Billed as the smallest size that covers both |
| `runtime` | `standard` | `standard` or `vm`. Leave it out and Fibre picks from `needs`. See [runtimes](https://docs.fibre.dev/sandboxes/runtimes.md) |
| `needs` | | What it must be able to do: `docker`, `fuse`, `cgroups`, `loop`, `iptables` (these pick `vm`), `browser`, `desktop` (started for you) |
| `init` | | `"systemd"`: the image's systemd runs as the first process (`vm` only) |
| `env_vars` (`env`) | | Environment variables for every command in the sandbox |
| `entrypoint` | the image's | The command the sandbox runs as its main program |
| `exposed_port` (`exposedPort`) | `8000` | The port its `url` serves. See [serve an app](https://docs.fibre.dev/connect/public-urls.md) |
| `ready` | `process` on the default image, with `init`, or for a desktop; `port` with your own `image` or `entrypoint` | When it counts as running. `process`: as soon as it runs, kept alive for you to run commands in. `port`: once its program answers on `exposed_port` |
| `lifetime_sec` (`lifetime`) | none | Seconds until it is deleted automatically: 60 up to 10 years. Without it, the sandbox is kept until you delete it. Change or remove it later |
| `idle_timeout_sec` (`idleTimeout`; `idle_timeout` in Python) | `300` | Quiet seconds before it sleeps: up to 86400; **`0` never sleeps** |
| `network` | open | `{"allow": ["pypi.org", "*.github.com"]}` to reach only those; `{"block": true}` for no network |
| `labels` | | Up to 16 key-value tags of yours |
| `snapshot` | | Start as a copy of a [snapshot](https://docs.fibre.dev/setup/snapshots.md): a sandbox saved with its memory |

> [!NOTE]
>
> A sandbox started from a snapshot takes its image, size, runtime and environment from that snapshot. When you use
> `snapshot`, you can only set `lifetime_sec`, `idle_timeout_sec` and `labels` yourself.

## Find it again

Your app needs a way to find a user's sandbox the next time they show up. You could store each sandbox's ID in your
own database, but there is a simpler way: **labels**. Because you tagged the sandbox with `user: 42`, you can
simply ask Fibre for "the sandboxes of user 42" and get it back, with nothing stored on your side.

```bash title="CLI" run theme={null}
fibre list --label user=42   # sbx-… running … user=42,task=fix-login

fibre get "$SBX"
```

```typescript title="TypeScript" run theme={null}
for await (const s of Sandbox.list({ labels: { user: "42" } })) {
  console.log(s.id, s.status, s.labels.task); // sbx-… running fix-login
}

const same = await Sandbox.get(sbx.id);
console.log(same.url, same.expiresAt);
```

```python title="Python" run theme={null}
for s in Sandbox.list(labels={"user": "42"}):
    print(s.id, s.status, s.labels["task"])  # sbx-… running fix-login

same = Sandbox.get(sbx.id)
print(same.url, same.expires_at)
```

```bash title="curl" run theme={null}
curl -sS "$FIBRE_API_URL/v1/sandboxes?label.user=42&limit=10" -H "Authorization: Bearer $FIBRE_API_KEY"
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "sandboxes": [
>     {
>       "id": "…",
>       "status": "running",
>       "labels": {
>         "user": "42",
>         "task": "fix-login"
>       }
>     }
>   ]
> }
> ```

A few details about listing:

* **Several labels narrow the list.** `?label.user=42&label.task=fix-login` returns only sandboxes that have both.
* **Results come newest first, 50 per page** (you can ask for up to 200 with `limit`). When there are more, the
  answer includes a `next_cursor`. Pass it back as `?cursor=` to get the next page. In the SDKs,
  `Sandbox.list()` does the paging for you.
* **To get one sandbox by its ID**, call `GET /v1/sandboxes/{id}`. This works for sleeping sandboxes too, and it
  does not wake them: you simply see `"status": "standby"`.

Label keys can use lowercase letters, digits, `.`, `_` and `-`, and can be up to 63 characters long. Values can be
up to 128 characters.

## Change it while it lives

Most settings are fixed once a sandbox is created. Three things can change while it runs: **how long it lives,
how quickly it goes to sleep, and its labels.** This is useful, for example, to give a busy user's sandbox more
time, or to mark a task as ready for review:

```bash title="CLI" run theme={null}
fibre update "$SBX" --lifetime 2h       # two more hours, from now
fibre update "$SBX" --idle-timeout 10m  # sleep after 10 quiet minutes
fibre update "$SBX" --label user=42 --label task=fix-login --label state=review
```

```typescript title="TypeScript" run theme={null}
await sbx.update({ lifetime: 7200 });                       // two more hours, from now
await sbx.update({ idleTimeout: 600 });                     // sleep after 10 quiet minutes
await sbx.update({ labels: { user: "42", task: "fix-login", state: "review" } });
console.log(sbx.expiresAt, sbx.labels.state); // 2026-… review
```

```python title="Python" run theme={null}
sbx.update(lifetime=7200)  # two more hours, from now
sbx.update(idle_timeout=600)  # sleep after 10 quiet minutes
sbx.update(labels={"user": "42", "task": "fix-login", "state": "review"})
print(sbx.expires_at, sbx.labels["state"])  # 2026-… review
```

```bash title="curl" run theme={null}
curl -sS -X PATCH "$FIBRE_API_URL/v1/sandboxes/$SBX" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "lifetime_sec": 7200,
    "idle_timeout_sec": 600,
    "labels": {"user": "42", "task": "fix-login", "state": "review"}
  }'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "id": "…",
>   "expires_at": "…",
>   "idle_timeout_sec": 600,
>   "labels": {
>     "user": "42",
>     "task": "fix-login",
>     "state": "review"
>   }
> }
> ```

> [!WARNING]
>
> Sending `labels` **replaces the whole set of labels**. To add one label, send it together with the labels you
> want to keep, as in the example above.

A new lifetime counts **from the moment you set it**, from 60 seconds up to 10 years. To remove it, so the sandbox
is kept until you delete it, send `"lifetime_sec": null` (`lifetime: null` in TypeScript, `lifetime=None` in Python,
`fibre update --no-lifetime` in the CLI).

## Retry without making two

Networks sometimes drop answers. If your request to create a sandbox times out, you cannot tell whether the
sandbox was created or not. If you simply try again, you might end up with two sandboxes, and pay for both.

The fix is an **idempotency key**: a unique value of your choosing, sent in the `Idempotency-Key` header. If Fibre
sees the same key twice, it does not create a second sandbox. It returns the first one instead. This example sends
the same request twice with the same key, and gets one sandbox back both times:

```bash title="curl" run theme={null}
KEY=$(uuidgen)
A=$(curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" -H "Idempotency-Key: $KEY" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" -d '{"lifetime_sec": 300}' | jq -r .id)
B=$(curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" -H "Idempotency-Key: $KEY" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" -d '{"lifetime_sec": 300}' | jq -r .id)
[ "$A" = "$B" ] && echo "one sandbox, asked for twice"
curl -sS -o /dev/null -X DELETE "$FIBRE_API_URL/v1/sandboxes/$A" -H "Authorization: Bearer $FIBRE_API_KEY"
```

> [accordion] Output
>
> ```text title="output" expected theme={null}
> one sandbox, asked for twice
> ```

* **Use a new key for each sandbox you mean to create.** A random UUID works well. Fibre remembers each key for 24
  hours.
* **Reusing a key with a different request is refused** (`422 idempotency_key_reused`), so a key can never be
  mixed up with another create.
* **The SDKs do this for you.** Every `Sandbox.create()` sends its own key, so the SDK's automatic
  retries never create a second sandbox.

## Delete it

```bash title="CLI" run theme={null}
fibre delete "$SBX"
```

```typescript title="TypeScript" run theme={null}
await sbx.delete();
```

```python title="Python" run theme={null}
sbx.delete()
```

```bash title="curl" run theme={null}
curl -sS -X DELETE "$FIBRE_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $FIBRE_API_KEY"
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "id": "…",
>   "deleted": true
> }
> ```

**Deleting a sandbox is final.** The machine, its files and its saved memory are all removed, and they cannot be
recovered. Asking for the sandbox afterwards returns `404 sandbox_not_found`.

**Fibre never deletes a sandbox on its own.** One you do not delete is kept, asleep while nothing happens in it,
and its storage counts towards your bill, unless you gave it a [lifetime](https://docs.fibre.dev/sandboxes/sleep-and-wake.md#lifetime).

To clean up everything that belongs to one user, list their sandboxes by label and delete each one:

```bash title="CLI" norun reason="shows the clean-up loop; the page's sandboxes are already deleted" theme={null}
fibre delete $(fibre list --label user=42 --json | jq -r '.[].id')
```

```typescript title="TypeScript" norun reason="shows the clean-up loop; the page's sandboxes are already deleted" theme={null}
for await (const s of Sandbox.list({ labels: { user: "42" } })) await s.delete();
```

```python title="Python" norun reason="shows the clean-up loop; the page's sandboxes are already deleted" theme={null}
for s in Sandbox.list(labels={"user": "42"}):
    s.delete()
```

> [!TIP]
>
> If a user might come back, **it is usually better to let the sandbox sleep than to delete it.** A sleeping
> sandbox costs nothing for compute and wakes up with everything in place. Delete a sandbox when the user clearly
> says they are done, for example by deleting their project, rather than on a timer.

## Errors

Every error has a message, a stable `code`, and a `request_id`.

| Status | Code | What to do |
| - | - | - |
| 400 | `validation_failed` | A field is wrong; `details` says which |
| 400 | `needs_vm` | A need such as `docker` was asked on `"runtime": "standard"`: drop `runtime`, or use `vm` |
| 400 | `init_needs_vm` | `init` needs `"runtime": "vm"` |
| 400 | `size_too_large` | More CPU or memory than the largest size |
| 400 | `snapshot_fields_fixed` | A copy of a snapshot was given a field it takes from the snapshot |
| 402 | `payment_required`, `subscription_required`, `trial_limit` | Billing: add funds, choose a plan, or stay inside the trial's limits |
| 403 | `image_not_owned` | The image belongs to another organization |
| 404 | `image_not_found`, `snapshot_not_found` | No such image or snapshot |
| 404 | `sandbox_not_found` | No sandbox with that ID: deleted, expired, or never yours |
| 422 | `idempotency_key_reused` | That key was used with a different request |
| 429 | `sandbox_limit` | You keep as many sandboxes as your plan allows, awake or asleep: delete some, or upgrade |
| 429 | `org_limit` | Your sandboxes use as much capacity as one account may: stop or delete some |
| 503 | `create_failed`, `no_capacity` | Nothing was left behind: **retry** (with the same `Idempotency-Key`) |

## Related

> [card] [Run commands](https://docs.fibre.dev/sandboxes/running-commands.md)
>
> Now that it runs, make it do something.

> [card] [Sleep and wake](https://docs.fibre.dev/sandboxes/sleep-and-wake.md)
>
> What a sandbox keeps while it sleeps.

> [card] [Runtimes](https://docs.fibre.dev/sandboxes/runtimes.md)
>
> When you need Docker or a full VM.

> [card] [API keys](https://docs.fibre.dev/get-started/api-keys.md)
>
> A key that works on one sandbox only.


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