# e2b-dev/firecracker architecture

> Architecture diagram of the GitHub repository e2b-dev/firecracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/e2b-dev/firecracker
- Repository: https://github.com/e2b-dev/firecracker

## Overview

#### Purpose and executables
Firecracker is a Rust/Linux microVM monitor for secure, multi-tenant container and function workloads. It runs one VMM process per microVM over Linux KVM. Primary binaries are Firecracker (`src/firecracker/src/main.rs`) and its production launcher/isolation wrapper, Jailer (`src/jailer/src/main.rs`). Workspace composition and dependencies are rooted in `Cargo.toml`.

#### Host API and lifecycle control
The Firecracker process exposes a host-side API defined by OpenAPI at `src/firecracker/swagger/firecracker.yaml`. The API server parses resource/action requests and routes them into VMM configuration and lifecycle operations: `src/firecracker/src/api_server/mod.rs`, `src/firecracker/src/api_server/request/mod.rs`, and `src/firecracker/src/api_server_adapter.rs`. This is the central boundary between an external orchestrator and in-process VM state; the guest does not directly access this API.

#### VMM construction and KVM execution
The VMM crate owns machine assembly, runtime state, and KVM-facing control. Its builder converts configured resources into a VM, memory map, vCPUs, buses, and devices (`src/vmm/src/builder.rs`, `src/vmm/src/vstate/vm.rs`, `src/vmm/src/vstate/vcpu.rs`). Architecture-specific KVM boot and register logic split across x86_64 and aarch64 (`src/vmm/src/arch/x86_64/kvm.rs`, `src/vmm/src/arch/aarch64/kvm.rs`). Linux KVM is therefore the fundamental external runtime dependency.

#### Configuration, resources, and CPU compatibility
API updates are represented as typed VMM configuration and resource state before or during VM creation (`src/vmm/src/vmm_config/mod.rs`, `src/vmm/src/resources.rs`, `src/vmm/src/rpc_interface.rs`). CPU templates normalize or constrain guest CPU exposure across host processors, with x86 CPUID and aarch64 implementations (`src/vmm/src/cpu_config/x86_64/cpuid/normalize.rs`, `src/vmm/src/cpu_config/aarch64/custom_cpu_template.rs`). The standalone CPU-template helper supports fingerprinting, generation, stripping, and verification (`src/cpu-template-helper/src/main.rs`).

#### Guest device and I/O plane
The device manager attaches legacy, MMIO, and PCI devices to guest buses (`src/vmm/src/device_manager/mod.rs`, `src/vmm/src/device_manager/mmio.rs`, `src/vmm/src/device_manager/pci_mngr.rs`). Virtio is the principal guest I/O boundary: block supports file-backed and vhost-user backends, net connects host TAP networking, and other devices include balloon, memory hotplug, RNG, PMEM, and vsock (`src/vmm/src/devices/virtio/block/virtio/device.rs`, `src/vmm/src/devices/virtio/net/tap.rs`, `src/vmm/src/devices/virtio/vsock/device.rs`). Block I/O can use asynchronous Linux io_uring (`src/vmm/src/io_uring/mod.rs`).

#### Isolation, syscall policy, and observability
Jailer establishes a production isolation boundary through chroot, cgroups, namespaces/environment setup, resource limits, and privilege reduction (`src/jailer/src/chroot.rs`, `src/jailer/src/cgroup.rs`, `src/jailer/src/env.rs`). Firecracker and VMM apply seccomp policies; the compiler and shipped architecture policies are separate (`src/seccompiler/src/lib.rs`, `src/firecracker/src/seccomp.rs`, `resources/seccomp/x86_64-unknown-linux-musl.json`). Logging and metrics flow through VMM logging/metrics components (`src/vmm/src/logger/mod.rs`, `src/firecracker/src/metrics.rs`).

#### Persistence and guest metadata
Snapshotting persists/restores VM state, device state, and memory-related metadata for cloning or rapid resume (`src/vmm/src/snapshot/mod.rs`, `src/vmm/src/persist.rs`, `src/snapshot-editor/src/main.rs`). MMDS is a guest-facing metadata datastore, exposed only when configured, with state persistence and token support (`src/vmm/src/mmds/data_store.rs`, `src/vmm/src/mmds/persist.rs`). These subsystems bridge host-provided state into a running or restored guest while remaining distinct from the host control API.

Main entry points: [`src/vmm/src/vstate/vm.rs`](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/vstate/vm.rs) (KVM VM and vCPUs), [`src/vmm/src/builder.rs`](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/builder.rs) (VMM builder), [`src/firecracker/src/main.rs`](https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/src/main.rs) (Firecracker), [`src/jailer/src/main.rs`](https://github.com/e2b-dev/firecracker/blob/main/src/jailer/src/main.rs) (Jailer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Host control plane"]
  node_firecracker{{"Firecracker<br/>VMM binary<br/>[main.rs]"}}
  node_openapi["Host API contract<br/>OpenAPI<br/>[firecracker.yaml]"]
  node_api_server["API server<br/>request router<br/>[mod.rs]"]
  node_api_adapter["VMM API adapter<br/>control bridge"]
end

subgraph group_runtime["VMM runtime"]
  node_vmm_config["Configuration and resources<br/>typed VM state<br/>[mod.rs]"]
  node_vmm_builder["VMM builder<br/>machine assembly<br/>[builder.rs]"]
  node_kvm_runtime["KVM VM and vCPUs<br/>virtualization runtime<br/>[vm.rs]"]
  node_linux_kvm[("Linux KVM<br/>host kernel interface")]
  node_cpu_templates["CPU compatibility<br/>CPU templates<br/>[normalize.rs]"]
  node_cpu_helper{{"CPU template helper<br/>CLI tool<br/>[main.rs]"}}
end

subgraph group_io["Guest I/O and state"]
  node_device_manager["Device manager<br/>guest bus assembly<br/>[mod.rs]"]
  node_virtio["Virtio devices<br/>guest I/O boundary<br/>[device.rs]"]
  node_io_uring["io_uring<br/>async block I/O<br/>[mod.rs]"]
  node_snapshots[("Snapshots<br/>VM persistence<br/>[mod.rs]")]
  node_mmds[("MMDS<br/>guest metadata store<br/>[data_store.rs]")]
end

subgraph group_isolation["Isolation and operations"]
  node_jailer{{"Jailer<br/>launcher binary<br/>[main.rs]"}}
  node_jailer_isolation["Chroot and cgroups<br/>isolation setup<br/>[chroot.rs]"]
  node_seccomp["Seccomp policy<br/>syscall sandbox<br/>[lib.rs]"]
  node_metrics["Logging and metrics<br/>observability<br/>[mod.rs]"]
end

node_workspace["Cargo workspace<br/>Rust workspace<br/>[Cargo.toml]"]

node_workspace -->|"builds"| node_firecracker
node_workspace -->|"builds"| node_jailer
node_jailer -->|"sets up"| node_jailer_isolation
node_jailer -->|"launches"| node_firecracker
node_openapi -->|"defines"| node_api_server
node_api_server -->|"routes requests"| node_api_adapter
node_api_adapter -->|"updates"| node_vmm_config
node_vmm_config -->|"configures"| node_vmm_builder
node_vmm_builder -->|"creates"| node_kvm_runtime
node_cpu_templates -->|"constrains CPU"| node_vmm_builder
node_kvm_runtime -->|"uses"| node_linux_kvm
node_vmm_builder -->|"attaches devices"| node_device_manager
node_device_manager -->|"manages"| node_virtio
node_virtio -.->|"uses for block I/O"| node_io_uring
node_snapshots -->|"restores and saves state"| node_kvm_runtime
node_mmds -->|"exposes to guest"| node_virtio
node_seccomp -->|"restricts syscalls"| node_firecracker
node_seccomp -->|"restricts syscalls"| node_kvm_runtime
node_firecracker -->|"emits telemetry"| node_metrics
node_kvm_runtime -->|"emits telemetry"| node_metrics
node_cpu_helper -->|"produces and verifies"| node_cpu_templates

click node_workspace "https://github.com/e2b-dev/firecracker/blob/main/Cargo.toml"
click node_jailer "https://github.com/e2b-dev/firecracker/blob/main/src/jailer/src/main.rs"
click node_jailer_isolation "https://github.com/e2b-dev/firecracker/blob/main/src/jailer/src/chroot.rs"
click node_firecracker "https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/src/main.rs"
click node_openapi "https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/swagger/firecracker.yaml"
click node_api_server "https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/src/api_server/mod.rs"
click node_api_adapter "https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/src/api_server_adapter.rs"
click node_vmm_config "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/vmm_config/mod.rs"
click node_vmm_builder "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/builder.rs"
click node_kvm_runtime "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/vstate/vm.rs"
click node_cpu_templates "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/cpu_config/x86_64/cpuid/normalize.rs"
click node_device_manager "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/device_manager/mod.rs"
click node_virtio "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/devices/virtio/block/virtio/device.rs"
click node_io_uring "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/io_uring/mod.rs"
click node_snapshots "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/snapshot/mod.rs"
click node_mmds "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/mmds/data_store.rs"
click node_seccomp "https://github.com/e2b-dev/firecracker/blob/main/src/seccompiler/src/lib.rs"
click node_metrics "https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/logger/mod.rs"
click node_cpu_helper "https://github.com/e2b-dev/firecracker/blob/main/src/cpu-template-helper/src/main.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_firecracker,node_openapi,node_api_server,node_api_adapter toneBlue
class node_vmm_config,node_vmm_builder,node_kvm_runtime,node_linux_kvm,node_cpu_templates,node_cpu_helper toneAmber
class node_device_manager,node_virtio,node_io_uring,node_snapshots,node_mmds toneMint
class node_jailer,node_jailer_isolation,node_seccomp,node_metrics toneRose
class node_workspace toneNeutral
```

## Components

### Host control plane

Host orchestration and VM lifecycle boundary.

- [Firecracker](https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/src/main.rs): VMM binary · One monitor process runs one microVM. · `src/firecracker/src/main.rs`
- [Host API contract](https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/swagger/firecracker.yaml): OpenAPI · `src/firecracker/swagger/firecracker.yaml`
- [API server](https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/src/api_server/mod.rs): request router · Accepts host resource and lifecycle requests. · `src/firecracker/src/api_server/mod.rs`
- [VMM API adapter](https://github.com/e2b-dev/firecracker/blob/main/src/firecracker/src/api_server_adapter.rs): control bridge · Translates API actions into in-process VMM operations. · `src/firecracker/src/api_server_adapter.rs`

### VMM runtime

Machine construction and KVM execution.

- [Configuration and resources](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/vmm_config/mod.rs): typed VM state · Represents configured resources before and during VM creation. · `src/vmm/src/vmm_config/mod.rs`
- [VMM builder](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/builder.rs): machine assembly · Builds memory, vCPUs, buses, and devices from resources. · `src/vmm/src/builder.rs`
- [KVM VM and vCPUs](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/vstate/vm.rs): virtualization runtime · Owns VM state and runs guest vCPUs through Linux KVM. · `src/vmm/src/vstate/vm.rs`
- **Linux KVM**: host kernel interface
- [CPU compatibility](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/cpu_config/x86_64/cpuid/normalize.rs): CPU templates · Normalizes or constrains guest CPU exposure across hosts. · `src/vmm/src/cpu_config/x86_64/cpuid/normalize.rs`
- [CPU template helper](https://github.com/e2b-dev/firecracker/blob/main/src/cpu-template-helper/src/main.rs): CLI tool · Generates, fingerprints, strips, and verifies CPU templates. · `src/cpu-template-helper/src/main.rs`

### Guest I/O and state

Guest-facing devices, metadata, and persistence.

- [Device manager](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/device_manager/mod.rs): guest bus assembly · Attaches legacy, MMIO, and PCI devices. · `src/vmm/src/device_manager/mod.rs`
- [Virtio devices](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/devices/virtio/block/virtio/device.rs): guest I/O boundary · Provides block, network, vsock, and other guest devices. · `src/vmm/src/devices/virtio/block/virtio/device.rs`
- [io_uring](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/io_uring/mod.rs): async block I/O · `src/vmm/src/io_uring/mod.rs`
- [Snapshots](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/snapshot/mod.rs): VM persistence · Persists and restores VM, device, and memory-related state. · `src/vmm/src/snapshot/mod.rs`
- [MMDS](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/mmds/data_store.rs): guest metadata store · Configured guest-facing metadata with persistence and tokens. · `src/vmm/src/mmds/data_store.rs`

### Isolation and operations

Production containment, syscall policy, and observability.

- [Jailer](https://github.com/e2b-dev/firecracker/blob/main/src/jailer/src/main.rs): launcher binary · Prepares the isolated execution environment for Firecracker. · `src/jailer/src/main.rs`
- [Chroot and cgroups](https://github.com/e2b-dev/firecracker/blob/main/src/jailer/src/chroot.rs): isolation setup · Applies chroot, cgroups, namespaces, limits, and privilege reduction. · `src/jailer/src/chroot.rs`
- [Seccomp policy](https://github.com/e2b-dev/firecracker/blob/main/src/seccompiler/src/lib.rs): syscall sandbox · Compiler and shipped policies restrict Firecracker and VMM syscalls. · `src/seccompiler/src/lib.rs`
- [Logging and metrics](https://github.com/e2b-dev/firecracker/blob/main/src/vmm/src/logger/mod.rs): observability · `src/vmm/src/logger/mod.rs`

### Other components

- [Cargo workspace](https://github.com/e2b-dev/firecracker/blob/main/Cargo.toml): Rust workspace · `Cargo.toml`

## Connections

- Cargo workspace → Firecracker: builds
- Cargo workspace → Jailer: builds
- Jailer → Chroot and cgroups: sets up
- Jailer → Firecracker: launches
- Host API contract → API server: defines
- API server → VMM API adapter: routes requests
- VMM API adapter → Configuration and resources: updates
- Configuration and resources → VMM builder: configures
- VMM builder → KVM VM and vCPUs: creates
- CPU compatibility → VMM builder: constrains CPU
- KVM VM and vCPUs → Linux KVM: uses
- VMM builder → Device manager: attaches devices
- Device manager → Virtio devices: manages
- Virtio devices → io_uring: uses for block I/O
- Snapshots → KVM VM and vCPUs: restores and saves state
- MMDS → Virtio devices: exposes to guest
- Seccomp policy → Firecracker: restricts syscalls
- Seccomp policy → KVM VM and vCPUs: restricts syscalls
- Firecracker → Logging and metrics: emits telemetry
- KVM VM and vCPUs → Logging and metrics: emits telemetry
- CPU template helper → CPU compatibility: produces and verifies
