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

# Runtimes: standard and VM

> Two ways a sandbox can run: standard for code, tools and browsers; vm, a full virtual machine with its own kernel, for Docker, systemd and kernel features. Same calls, same price.

A **runtime** is the way a sandbox runs underneath. Fibre has two of them, and every sandbox uses one. In practice
you rarely choose one by name: **you describe what the sandbox needs to do, and Fibre picks the runtime that can
do it.**

* **`standard`** is the default. It runs code, scripts, package installs, tests, dev servers and browsers, which
  covers what most agents and apps need.
* **`vm`** is a full virtual machine with **its own Linux kernel**. Some software needs a kernel of its own to
  work, for example **Docker**, services managed by systemd, mounting filesystems, or firewall rules. For that kind
  of work, `vm` is the runtime to use.

Both runtimes use the same API, sleep and wake in the same way, and **cost the same for each size**. Moving a
workload from one to the other is a one-word change.

## Which one do I need?

Find what you want to do in the left column. The last column shows what to put in your create request:

| You want to | Runtime | Ask for it with |
| - | - | - |
| Run code, tests, a dev server, a coding agent | `standard` | Nothing: it is the default |
| Drive a browser with Playwright or Puppeteer | either | `"needs": ["browser"]` |
| **Run Docker or Docker Compose inside** | `vm` | `"needs": ["docker"]` |
| Run services under systemd, as on a server | `vm` | `"init": "systemd"` |
| Mount FUSE filesystems or loop devices | `vm` | `"needs": ["fuse"]`, `["loop"]` |
| Set firewall rules or cgroup limits inside | `vm` | `"needs": ["iptables"]`, `["cgroups"]` |
| Give an agent a desktop to see and click | `vm` | `"needs": ["desktop"]` |

## Say what you need

The easiest way to get the right runtime is to list what the sandbox needs in `needs`. Fibre then picks the
runtime that has it, and the answer tells you which runtime it picked and why:

```bash title="CLI" run theme={null}
PROBE=$(fibre create --needs docker --lifetime 5m --label docs=runtimes --json | jq -r .id)
fibre get "$PROBE"   # runtime: vm (needs:docker)
fibre delete "$PROBE"
```

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

const probe = await Sandbox.create({ needs: ["docker"], lifetime: 300, labels: { docs: "runtimes" } });
console.log(probe.runtime, probe.runtimeReason); // vm needs:docker
await probe.delete();
```

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

probe = Sandbox.create(needs=["docker"], lifetime=300, labels={"docs": "runtimes"})
print(probe.runtime, probe.runtime_reason)  # vm needs:docker
probe.delete()
```

```bash title="curl" run capture=PROBE=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"needs": ["docker"], "lifetime_sec": 300, "labels": {"docs": "runtimes"}}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "id": "…",
>   "status": "running",
>   "runtime": "vm",
>   "runtime_reason": "needs:docker"
> }
> ```

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

The `runtime_reason` field explains the choice:

| `runtime_reason` | Means |
| - | - |
| `default` | Nothing asked for a VM: `standard` |
| `needs:docker` (or another need) | That need requires a VM |
| `requested` | You named the runtime yourself |
| `snapshot` | It is a copy of a snapshot, and runs where the snapshot was made |

## Docker inside a sandbox

Because a `vm` sandbox has its own kernel, it can run Docker. That means **an agent can build and run containers**
just as it would on a laptop: start a database for its tests, build the project's image, or run
`docker compose up`.

In this example, a sandbox starts from Docker's official image, which runs the Docker daemon. Then it starts Redis
in a container and stores and reads a value, to show that everything works.

**1. Start a VM sandbox with Docker**

```typescript title="TypeScript" run theme={null}
const sbx = await Sandbox.create({
  image: "docker:27-dind",
  needs: ["docker"],
  entrypoint: ["sh", "-c", "dind dockerd > /var/log/dockerd.log 2>&1"],   // the Docker daemon is its main program
  size: "medium",
  lifetime: 900,
  labels: { docs: "runtimes" },
});
console.log(sbx.runtime); // vm
```

```python title="Python" run theme={null}
sbx = Sandbox.create(
    image="docker:27-dind",
    needs=["docker"],
    entrypoint=["sh", "-c", "dind dockerd > /var/log/dockerd.log 2>&1"],  # the Docker daemon is its main program
    size="medium",
    lifetime=900,
    labels={"docs": "runtimes"},
)
print(sbx.runtime)  # vm
```

```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 '{
    "image": "docker:27-dind",
    "needs": ["docker"],
    "entrypoint": ["sh", "-c", "dind dockerd > /var/log/dockerd.log 2>&1"],
    "size": "medium",
    "lifetime_sec": 900,
    "labels": {"docs": "runtimes"}
  }'
```

**2. Run a container and use it**

Downloading a container image can take longer than the 30 seconds an exec allows, so this runs as a
[background command](https://docs.fibre.dev/sandboxes/running-commands.md) that you wait for. The command first waits until the Docker
daemon is ready.

```typescript title="TypeScript" run theme={null}
const redis = await sbx.run([
  "until docker info > /dev/null 2>&1; do sleep 1; done",        // wait for the daemon
  "docker run -d --name cache redis:7-alpine > /dev/null",
  "sleep 2",
  "docker exec cache redis-cli set greeting 'hello from a container'",
  "docker exec cache redis-cli get greeting",
].join(" && "), { timeout: 300 });
console.log(redis.stdout); // OK \n hello from a container
```

```python title="Python" run theme={null}
redis = sbx.run(" && ".join([
    "until docker info > /dev/null 2>&1; do sleep 1; done",  # wait for the daemon
    "docker run -d --name cache redis:7-alpine > /dev/null",
    "sleep 2",
    "docker exec cache redis-cli set greeting 'hello from a container'",
    "docker exec cache redis-cli get greeting",
]), timeout=300)
print(redis.stdout)  # OK \n hello from a container
```

```bash title="curl" run capture=CMD=.command_id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$SBX/commands" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "until docker info > /dev/null 2>&1; do sleep 1; done && docker run -d --name cache redis:7-alpine > /dev/null && sleep 2 && docker exec cache redis-cli set greeting \"hello from a container\" && docker exec cache redis-cli get greeting"]}'
```

```bash title="curl: its output" run theme={null}
curl -sSN "$FIBRE_API_URL/v1/sandboxes/$SBX/commands/$CMD/logs?follow=1" -H "Authorization: Bearer $FIBRE_API_KEY"
```

> [accordion] Output
>
> ```text title="output" expected theme={null}
> hello from a container
> ```

**3. Delete it**

```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"
```

> [!TIP]
>
> **On `vm`, sleep keeps every process, including your containers.** If a sandbox with a running `docker compose`
> stack goes to sleep, the next call finds the whole stack still up, with all its data.

## systemd, like a server

On a typical Linux server, **systemd** is the first program that starts, and it starts and supervises all the
others. With `"init": "systemd"`, a `vm` sandbox works the same way: the image's systemd runs first, and any
services you enable start with the machine and come back after every wake. The result is a sandbox that behaves
like a small server. You need an image that includes systemd:

```typescript title="TypeScript" norun reason="needs an image whose first process can be systemd" theme={null}
const machine = await Sandbox.create({ image: "<an image with systemd>", runtime: "vm", init: "systemd" });
```

```python title="Python" norun reason="needs an image whose first process can be systemd" theme={null}
machine = Sandbox.create(image="<an image with systemd>", runtime="vm", init="systemd")
```

```bash title="curl" norun reason="needs an image whose first process can be systemd" theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"image": "<an image with systemd>", "runtime": "vm", "init": "systemd"}'
```

## Naming the runtime yourself

You can also choose the runtime directly, with `"runtime": "standard"` or `"runtime": "vm"`. If you then ask
for something that runtime cannot provide, Fibre refuses the request rather than quietly ignoring the need. This
way a sandbox always either has what you asked for, or does not start at all:

```bash title="CLI" run expect-exit=3 theme={null}
fibre create --runtime standard --needs docker   # error: … (needs_vm), exit code 3
```

```typescript title="TypeScript" run theme={null}
try {
  await Sandbox.create({ runtime: "standard", needs: ["docker"] });
} catch (e) {
  if (!(e instanceof FibreError)) throw e;
  console.log(e.status, e.code); // 400 needs_vm
}
```

```python title="Python" run theme={null}
try:
    Sandbox.create(runtime="standard", needs=["docker"])
except FibreError as e:
    print(e.status, e.code)  # 400 needs_vm
```

```bash title="curl" run theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"runtime": "standard", "needs": ["docker"]}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "code": "needs_vm",
>   "error": "…",
>   "request_id": "…"
> }
> ```

## What differs, and what does not

For reference, here is everything that differs between the two runtimes, and everything that stays the same:

| | `standard` | `vm` |
| - | - | - |
| Its own Linux kernel | No | **Yes** |
| Docker, systemd, FUSE, loop, iptables, cgroups | No | **Yes** |
| Processes after a sleep | The main program and those started with `keep` | **All of them** |
| [Snapshots](https://docs.fibre.dev/setup/snapshots.md) | Yes | Yes, once its commands have ended |
| API, SDK, files, commands | The same | The same |
| Sleep, wake, lifetime, labels | The same | The same |
| Price per size | The same | The same |

## Errors

These errors are about runtimes:

| Status | Code | When |
| - | - | - |
| 400 | `needs_vm` | A need that requires a VM, with `"runtime": "standard"` |
| 400 | `init_needs_vm` | `init` without `"runtime": "vm"` |

## Related

> [card] [Sleep and wake](https://docs.fibre.dev/sandboxes/sleep-and-wake.md)
>
> What each runtime keeps across a sleep.

> [card] [Browser](https://docs.fibre.dev/connect/browser.md)
>
> A browser for Playwright, on either runtime.

> [card] [Desktop](https://docs.fibre.dev/connect/desktop.md)
>
> A full desktop on a VM.

> [card] [Sizes and what is installed](https://docs.fibre.dev/sandboxes/sizes.md)
>
> CPU, memory and disk for each size.


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