Configuration

Runs and Firecracker

Run a command once in a Docker container or a Firecracker microVM, and set up Firecracker on the host.

A run executes one command in a fresh instance, records how it ended, and keeps its output and the files you ask for. The instance is removed afterwards. A build, a test suite or code written by an AI model are typical runs.

Each run picks a runtime. docker starts a container that shares the host kernel, so use it for code you trust. firecracker starts a microVM with its own kernel, so a run cannot reach the host kernel directly.

Start a run

Open Runs in the dashboard and select New run, or send the same fields to the API with a key that has the runs:write permission:

curl -X POST https://flatrun.example.com/api/runs \
  -H "Authorization: Bearer $FLATRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "runtime": "firecracker",
    "image": "node:22-alpine",
    "command": ["sh", "-c", "npm test > /out/report.txt"],
    "secret_env": { "NPM_TOKEN": "your-token-here" },
    "timeout_seconds": 600,
    "artifact_paths": ["/out/report.txt"]
  }'

The answer is 202 with the run record. Read GET /api/runs/:id for its status, GET /api/runs/:id/logs?follow=true to stream its output, and GET /api/runs/:id/artifacts/report.txt to download a kept file as a tar archive. DELETE /api/runs/:id cancels it.

FieldMeaning
runtimedocker (the default) or firecracker
imageAny image reference. A missing image is pulled.
commandThe command and its arguments
envEnvironment variables, stored with the run
secret_envEnvironment variables that are never stored, and are replaced by [REDACTED] in the output
egressNetwork access. Off by default.
timeout_seconds1 to 3600. Defaults to 600.
cpus, memory_bytesLimits. Firecracker rounds CPUs up to whole vCPUs and defaults to 256 MiB of memory.
artifact_pathsUp to 16 absolute paths to keep after the run
Kept files are not redacted. Secret values are removed from the output, but files listed in artifact_paths are copied as they are. Do not write secrets into them.

How a run ends

A run is succeeded when its command exits with code 0 and its output is collected and its instance removed. A missing kept file is recorded as an error but does not fail the run. Any other exit or error makes it failed, an expired timeout makes it timed_out, and a cancellation makes it cancelled. The timeout starts when a worker picks the run up, not while it waits in the queue. If the agent restarts, unfinished runs are marked failed and their instances are removed. They are not resumed.

Admins see every run, unless their API key is restricted to some deployments. Everyone else sees only their own runs, and viewers can read but not start them.

Configure runs

runs:
  workers: 2
  egress_subnet: ""
  firecracker:
    binary: firecracker
    jailer: jailer
    kernel: ""
    state_dir: /var/lib/flatrun/firecracker
    chroot_base_dir: /srv/jailer
    guest_init: ""
    default_memory: 268435456

workers is how many runs execute at once. Up to 128 more wait in the queue. Records, output and kept files are stored under <deployments_path>/.flatrun/ on the server that ran them, and are not deleted automatically.

Set up Firecracker

Firecracker stays off until runs.firecracker.kernel names a guest kernel. The host needs:

  • Linux 5.3 or newer, the agent running as root, and /dev/kvm
  • Static firecracker and jailer binaries of the same version
  • mkfs.ext4, ip, iptables and ip6tables
  • A guest kernel with ext4, virtio block, vsock and net, and IP autoconfiguration (CONFIG_IP_PNP)
  • The guest init, built with make guest-init and installed beside the agent, or named by guest_init

GET /api/runs/runtimes lists each runtime and, when one is unavailable, why. A run that asks for an unavailable runtime is refused with 503. Docker runs keep working.

The jail directory must allow device nodes. Each microVM runs in a jail under chroot_base_dir. If that filesystem is mounted with nodev, the VM cannot open KVM. The default /srv/jailer also keeps socket paths under the 108 byte Unix limit.

How the microVM is built

The agent exports the image through Docker into an ext4 filesystem and caches it by image digest. Each run gets its own copy, so runs never share a writable disk. The guest stays up after the command exits so kept files can be collected, then the VM, its jail, its disk copy and its network device are removed.

Network

Without egress, a microVM has no network device at all. With it, the VM gets its own tap device and reaches the internet through NAT. Firewall rules block the host, private address ranges, other VMs and IPv6. Egress needs IPv4 forwarding enabled on the host. Docker runs with egress join a shared bridge. When FlatRun creates that bridge it turns off traffic between containers.

Star us on GitHub