← Back to research
•·9 min read·opensource

libkrun

libkrun embeds a microVM in a calling process through a C API. Its device interfaces, host restrictions, and separately licensed kernel bundle are central to a secure integration.

Key takeaways

  • libkrun is an embeddable VM library; its callers still own filesystem, network, image, and lifecycle policy.
  • The documented security model treats guest and VMM as one context, requiring host restrictions around exposed resources.
  • GPU acceleration is available, but maintainers distinguish untrusted-workload risks across GPU protocols.
  • libkrun is Apache-2.0; libkrunfw separately bundles GPL-2.0 Linux code with an LGPL-2.1 library wrapper.

FAQ

What is libkrun?

A Rust VM library with a C API for embedding virtualized workloads in a host process. The current tagged release documents Linux KVM and macOS ARM64 Hypervisor.framework support.

Does a libkrun VM isolate arbitrary host files automatically?

No. The project explicitly requires host-side restrictions around the VMM, especially when exposing virtio-fs and TSI networking.

Does libkrun eliminate kernel and filesystem management?

libkrunfw supplies a bundled Linux kernel, and the API also supports external kernels. Callers still supply and govern guest filesystems, devices, images, and updates.

How much does libkrun cost?

It is free software, with infrastructure and integration costs borne by the caller. Its Apache-2.0 license does not replace the separate licenses of the bundled kernel and firmware package.

Executive Summary

libkrun embeds a virtual machine monitor in the process that links it. Written in Rust, it exposes a C interface for configuring and launching workloads. It is a building block for a runtime, rather than a hosted sandbox service.[1][2]

The important design constraint is resource authority. The project treats guest and VMM as the same security context: virtual devices can proxy access to the host. Embedders must constrain the VMM's host permissions and choose which devices to expose. A separate guest kernel does not automatically make a shared directory or GPU interface safe for a hostile guest.[3][4]

AttributeVerified September 15, 2026
Canonical repositorylibkrun/libkrun; the old containers URL redirects here[1]
Latest releasev1.19.4, July 3, 2026[5]
Repository activity2,688 stars, 265 forks; pushed September 15, 2026[1]
Library licenseApache-2.0[1]
Released host pathsLinux KVM and macOS ARM64; macOS build requirements specify version 14 or newer[4]

See the container-to-VM runtimes comparison for category context. This profile distinguishes the latest tagged release from ongoing main-branch development.


Product Overview

The API configures VM resources, disks, shared filesystems, environment, executable, and kernel. The companion libkrunfw supplies a Linux kernel as a dynamic library; the API also accepts an external kernel and initramfs. Callers still need a guest filesystem and an update strategy.[2][6]

IntegrationVerified role
crun krun modeOCI container runtime invokes libkrun for an additional VM layer; VM settings can be supplied through OCI annotations or image configuration[7]
krunkitmacOS VM launcher using libkrun; current README requires macOS 14+[8]
RamaLamaRed Hat's July 2025 article demonstrates model serving with Podman and the krun runtime; that article describes CPU inference on Linux[9]
NVIDIA OpenShellDocuments libkrun as a MicroVM backend on macOS and Linux[10]

These establish integrations, not deployment counts or a universal production certification.

What an embedding application must implement

The v1.19.4 C API makes the integration sequence concrete:[2]

StepAPI and responsibility
Allocate configurationkrun_create_ctx() returns a context ID or a negative error; check the result before using it
Size the guestkrun_set_vm_config() sets vCPU count and RAM in MiB
Supply a filesystemkrun_set_root() exposes a host directory; the more flexible virtio-fs API supports explicit read-only and mapping options
Select the workloadkrun_set_exec() configures the executable, arguments, and environment; krun_set_workdir() chooses its guest working directory
Enter executionkrun_start_enter() consumes the context and takes control of the calling process

Passing a null environment pointer to krun_set_exec() imports the host process's environment. An agent host should deliberately construct the guest environment rather than accidentally handing it inherited API tokens. That is an integration decision, not a default credential broker supplied by libkrun.[2]

krun_start_enter() is also not a normal function that returns after a successful job. It assumes control of the process and exits it when the VM shuts down, using the workload's exit status. A long-running application therefore needs an appropriate worker-process lifecycle around that API, including startup errors and cancellation. Check every configuration call, and free unused contexts with krun_free_ctx().[2]

Before entering the VM, the surrounding runtime must constrain the host resources that the VMM can reach. A root_path parameter alone does not create the documented host mount boundary. This is why crun's retained container restrictions and a carefully chosen device set matter as much as the small embedding API.[4][3]


Technical Architecture

Devices and networking

The v1.19.4 library includes configurable virtio devices for storage, shared files, networking, sockets, graphics, and other guest services. Its TSI socket transport and conventional virtio-net networking are alternative paths.[4]

PathConsequence for an integrator
TSIUses a custom guest kernel and proxies supported sockets through the VMM; raw sockets and guest datagram listeners are unsupported[4]
virtio-netUses an explicit network interface and supporting userspace network component such as passt or gvproxy[4]
virtio-fsRequires host mount isolation; simply selecting a shared directory is not the documented security boundary[4]
Disk imagesNon-raw images may reference host files. The API warns against opening untrusted non-raw images or re-probing a disk after a guest could modify it[2]

GPU performance and risk

The macOS stack forwards Vulkan work through virtio-gpu/Venus and host graphics libraries. Kevin Pouget's June 2025 Red Hat benchmark reported 0.52 tokens/second for a CPU configuration versus 20.84 for an updated Vulkan configuration: roughly 40× for that comparison, not a general libkrun speedup.[11]

The test used a 48GB M4 Pro MacBook, macOS 15.5, krunkit 0.1.4, RamaLama 0.7.0/0.9.0, and primarily Llama 3.1 8B. It combined GPU enablement with llama.cpp backend changes. This review did not reproduce it, and it does not establish superiority over every other VM runtime.[11]

Performance also does not establish security. Maintainer Sergio López's July 17, 2026 clarification identifies GPU command protocols as unsuitable for untrusted workloads, except the restricted DRM native-context path. Evaluate the specific graphics transport rather than treating all GPU support as equivalent.[3]

Confidential-computing variants

The tagged README documents AMD SEV variants, including SEV-ES/SNP and remote attestation, and Intel TDX. It also lists a macOS EFI flavor for distribution-provided kernels. Hardware and firmware requirements differ; the released TDX documentation limits guests to one vCPU and 3,072 MiB.[4]

Current main-branch documentation describes a newer TD-Shim path that lifts the legacy qboot limit. That should not be silently substituted for the v1.19.4 support contract.[1]


Strengths

  • Embedding gives the caller direct control. A C API exposes the VM configuration without requiring a separate service interface.[2]
  • Existing runtimes demonstrate composition. crun combines the VM with its container setup, and OpenShell offers it behind a compute driver.[7][10]
  • macOS acceleration has published evidence. The Red Hat experiment provides versions, hardware, workload, and test artifacts rather than only an unqualified speed claim.[11]
  • Maintenance is visible. June and July releases include filesystem identity/permission fixes; v1.19.4 specifically adjusts macOS virtio-fs security-context behavior.[5]

Cautions

  • Host policy remains the caller's job. Shared-file and socket interfaces must be contained by the host context; filesystem space and inode exhaustion also need host controls.[4]
  • Devices change the threat model. The maintainer recommends additional host isolation or a restricted device set for fully untrusted guests. A guest compromise does not automatically yield host root, but can expose the privileges of the linking process.[3]
  • Image handling is security-sensitive. Explicitly preserve known disk formats and trust requirements across guest writes and restarts.[2]
  • Published performance is workload-specific. A downstream startup claim cannot serve as a measured boot guarantee for every libkrun integration.
  • Released and development behavior differ. Pin the library, kernel bundle, device configuration, and downstream runtime together; a main-branch feature is not necessarily in the latest tag.[5][1]

What Developers Say

In discussion #538, opened February 9, 2026, developer codethief asks whether libkrun alone meets an untrusted-workload threat model. López explains that crun retains its normal container isolation before entering libkrun, combining both boundaries. Follow-up questions in July focus on deliberately exposed device interfaces. This is useful primary maintainer clarification prompted by a prospective user's concern; it is not an independent penetration test.[3]

The current security-model documentation incorporates the underlying caution. This review did not run a VM, reproduce the GPU benchmark, or test escapes.


Pricing & Licensing

ComponentPublished license
libkrun libraryApache-2.0[1]
libkrunfw Linux kernel and patchesGPL-2.0-only[6]
libkrunfw library wrapperLGPL-2.1-only[6]

The firmware project's README describes source-distribution requirements for its binary package. Its licensing is distinct from the library that consumes it. There is no usage charge for the source code; compute, packaging, lifecycle management, and support are separate engineering and operating costs.[6][1]


Competitive Positioning

The relevant choice is whether an application needs an embedded VM component and can own the surrounding policy. Teams seeking a complete execution service should evaluate that service's actual implementation; the presence of libkrun underneath it does not prove its isolation configuration.

Compare the profiles for Firecracker, Cloud Hypervisor, and Apple Containerization when selecting a VM stack. Microsandbox and OpenShell are useful higher-level evaluation contexts. This report does not rank their security from architecture labels alone.


Ideal Customer Profile

Best fit: runtime and developer-tool authors who want VM configuration in their application and can review device exposure, host restrictions, image trust, and guest updates.

Poor fit: teams expecting the library itself to supply a sandbox API, fleet operations, or a complete policy for mutually untrusted tenants.


Viability Assessment

The July release, September repository activity, and documented downstream integrations support an active-project assessment. Red Hat's technical articles establish engineering involvement, but do not establish a guaranteed funding level or support contract. Repository popularity also does not measure escape resistance.[5][1][9][10]


Bottom Line

libkrun is a practical building block when VM configuration belongs inside an application. Evaluate the complete host-and-guest design, especially shared files, disk formats, network proxying, and GPU transport.

Recommended for: builders able to maintain the policy and lifecycle around an embedded VMM.

Not recommended for: assuming hardware virtualization alone limits every host resource exposed through a device.

Outlook: follow tagged releases and downstream configurations; assess emerging features against a pinned, tested deployment.


Research by Ry Walker Research • methodology