Building a VMM from scratch, #0: Why BoxLite is replacing libkrun
Recorded: Oct. 12, 2026, 5:10 a.m.
| Original | Summarized |
Building a VMM from scratch, #0: Why BoxLite is replacing libkrunSkip to contentNew accounts start with $100 in credits Get an API key →CloudOpen SourcePricingDocsBlogDiscordGitHubGet an API key← all postsBuilding a VMM from scratch, #0: Why BoxLite is replacing libkrunPart #0 of a build-in-public series: what BoxLite is, why we started on libkrun, why we're replacing it, and how a VMM works.Dorian ZhengOct 11, 20266 min readEvery BoxLite box runs in its own micro-VM, and today libkrun runs that VM. We're replacing it with a VMM we write ourselves. This series builds it in public, one merged PR at a time. Figure 1. One engine in two places: the embedded BoxLite runtime starts one micro-VM per box, on your machine or on a cloud runner. A library, not a daemon: BoxLite embeds in your app, with no root and no background service. libkrun is how BoxLite runs boxes on macOS and Linux today. The VM's outcome. libkrun ends the process itself, so the caller gets no exit status, and every start failure comes back as -EINVAL. What we're not doing Forking or patching libkrun. It ships unchanged until the new VMM is the default, stays one release as a fallback, and is then removed. What it costs The new VMM needs macOS 15 or later, for Hypervisor.framework's in-kernel interrupt controller. macOS 12–14 keep libkrun until cutover. 4. How a VMM works, in one screen Figure 2. Inside one machine. The runtime spawns a jailed boxlite-shim per box, and the VMM inside it runs the micro-VM. PROPOSED marks what this series replaces. Figure 3. Run a vCPU until it exits, handle the exit, and run it again. Everything else is detail, and each detail gets a part in this series: PieceWhat it isPart MemoryGuest RAM is host memory; an unmapped address is a device#1 ExitsOne exit contract for KVM, Hypervisor.framework and, later, WHP#2 StoppingPulling a vCPU out of the guest, safely#3 CPU stateRegisters, CPUID and MSRs on x86#4 BootThe VMM is the bootloader#6 DevicesSerial, RTC and reset first, then virtio#7, #10–12 5. The series ArcPartsShips when 1. First instructions#1 Your first VM is 7 bytes · #2 Design the exit contract first · #3 Stopping a vCPU is the hard part · #4 x86 CPU state, by hand · #5 A kernel we build ourselvesCode merged 2. First boot (M1)#6 You are the bootloader · #7 Boring devices first · #8 On Apple silicon, you decode the exits · #9 One kernel, three hostsAs M1 lands 3. First box (M2–M3)#10 virtio from scratch · #11 Disks, sockets, network · #12 One virtio-fs device for every volume · #13 Our agent as PID 1M2–M3 4. Ship it (M4–M5)#14 Guest input must never panic the host · #15 Measured against libkrun · #16 Deleting libkrunM4–M5 LaterMemory snapshots, hot-plug mounts, GPUs, our own network stackAfter M5 Where we are ✅ Design and one hypervisor contract for KVM, Hypervisor.framework and, later, Windows Follow along on the RSS feed and in every PR on GitHub. Challenge the design. Read the VMM design doc and tell us where it's wrong. Start with CONTRIBUTING.md. Your first PR asks you to sign our contributor license agreement. |
The project detailed by Dorian Zheng focuses on building a Virtual Machine Monitor (VMM) from scratch to replace libkrun, which currently serves as the virtualization layer for BoxLite, a compute substrate designed for embedding AI agents onto local hardware while providing elasticity for agentic cloud deployment. BoxLite achieves this by running each instance within its own hardware-isolated micro-VM that maintains state across execution turns. The core of this effort involves developing the VMM, which is the component responsible for managing these micro-VMs on top of existing hypervisors like KVM or Apple's Hypervisor.framework. The motivation for replacing libkrun stems from its limitations regarding comprehensive virtualization capabilities. While libkrun offered a simple C API based on KVM and HVF, it was not designed to function as a generic VMM capable of handling advanced workload requirements. Specific shortcomings included insufficient handling of VM exit statuses, issues related to the kernel being treated as a shared library which caused instability on some hosts, and inadequate management of device interactions, where each directory volume required its own device allocation. Furthermore, the project aims to incorporate advanced features necessary for a complete VMM, such as hot-plug mounts, live resizing, memory snapshots, and GPU management. The plan is not to patch libkrun but to build a new, general-purpose VMM that incorporates these advanced features. The conceptual operation of the proposed VMM is based on a fundamental loop: the VMM acts as the ordinary process situated around the hypervisor, directing the execution of guest instructions on the CPU. It is responsible for providing memory and virtual CPUs to the guest, loading the guest kernel, emulating necessary devices, and managing the guest's lifecycle. The central continuous operation involves running a virtual CPU until it exits, successfully handling the exit condition, and then running the next virtual CPU. Detailed aspects of this mechanism encompass managing guest memory, defining an exit contract for hypervisors, safely pausing or stopping a virtual CPU, tracking CPU state information such as registers and MSRs, and managing device emulation, including serial ports and virtio interfaces. The development is executed through a structured, phased series of contributions designed to build the VMM incrementally. The initial stages focus on establishing core contracts, such as defining the exit contract, safely stopping a virtual CPU, and handling the operational details of x86 CPU state and boot processes. Subsequent stages build upon this foundation to implement the necessary components for a functional system. This roadmap progresses from implementing the first instructions and kernel structure to establishing the first boot on various platforms, then creating the first box infrastructure involving virtual disk and network devices. The final stages focus on hardening the system, ensuring guest input cannot compromise the host, and eventually removing the dependency on libkrun to achieve a fully realized VMM capable of supporting features like memory snapshots and dynamic device management. The project is open source, inviting community involvement to test designs, contribute code, and challenge the architectural decisions throughout this extensive development process. |