Hyperlight Documentation
repository·main·Indexed 26 days ago
https://github.com/hyperlight-dev/hyperlightA lightweight VMM designed for running untrusted code in hypervisor-isolated micro VMs with millisecond startup times and microsecond function call latency. Optimized for high-density environments like functions-as-a-service (FaaS), Hyperlight provides libraries for implementing hosts and guests in Rust and C, including hyperlight-libc based on picolibc 1.8.11 and the hyperlight_guest_capi for C-API integration.
What's inside Hyperlight
- Hyperlight is a library designed to run hypervisor-isolated workloads without the overhead of a full guest operating system. It is optimized for high-density, low-latency execution environments like functions-as-a-service (FaaS).
Create Hyperlight guests in C using hyperlight_guest_capi
mainThe
hyperlight_guest_capicrate provides a C-API wrapper overhyperlight-guest/hyperlight-guest-bin, enabling the development of Hyperlight guests using the C language. It generates platform-specific library files (.libor.a) and the necessary header files for integration.For a practical implementation reference, see the
c_simpleguestexample in thetests/c_guests/c_simpleguest/directory.Understand the Hyperlight security model and threat model
mainHyperlight is designed to safely execute untrusted or potentially malicious guest code without compromising the host. The security model is built on three pillars:
- Hypervisor Isolation: Guest code runs in a Virtual Machine with access only to a pre-allocated memory buffer. No dynamic memory allocation is allowed, and no devices (files, network, etc.) are provided by default.
- Strict Communication: Host-guest communication occurs via a shared memory buffer using FlatBuffers. The host enforces strong typing by only accepting data that matches the formal FlatBuffer schemas defined in the project.
- Controlled Function Exposure: Guests can only access host functionality that has been explicitly registered and exposed by the host application. Any attempt to call unregistered functions will result in an error.
Determine when to use Hyperlight
mainUse Hyperlight when:
- You need hypervisor-level isolation for untrusted or third-party code.
- You require millisecond startup times for sandboxes.
- You need microsecond latency for guest function calls.
- You want to embed sandboxed execution directly into an application.
- You are building functions-as-a-service (FaaS) with hypervisor isolation.
- You need to reuse sandboxes efficiently via snapshot/restore.
Do NOT use Hyperlight for:
- General-purpose virtualization (use a full VMM instead).
- Running full Linux guest workloads that require syscalls, networking, or filesystem access.
Understand the Hyperlight snapshot on-disk format
mainHyperlight serializes a
Snapshotto disk using the [OCI Image Layout] standard. This allows snapshots to be managed similarly to container images.Directory Layout
A snapshot directory contains:
oci-layout: Specifies the OCI layout version.index.json: Contains manifest descriptors for each tag, using theorg.opencontainers.image.ref.nameannotation.blobs/sha256/: A content-addressable store containing:- manifest: A JSON pointer (
application/vnd.oci.image.manifest.v1+json) referencing a config and a layer. - config: The snapshot descriptor (
application/vnd.hyperlight.snapshot.config.v1+json) containing architecture, hypervisor, CPU vendor, ABI version, registers, and memory layout. - layer / memory: The raw guest memory image (
application/vnd.hyperlight.snapshot.memory.v1) of exactlymemory_sizebytes.
- manifest: A JSON pointer (
Understand Hyperlight VM execution model
mainHyperlight is designed for creating micro virtual machines (VMs) optimized for small, short-running functions. Unlike traditional VM platforms, Hyperlight provides only minimal hardware isolation (vCPU and virtual memory) and shared memory between the host and the in-VM process (the "guest").
To achieve high efficiency and low latency, Hyperlight excludes several standard VM features:
- No Bootloader or OS kernel
- No Virtual networking
- No Virtual filesystem
This makes it suitable for lightweight function execution rather than long-running, complex workloads.
Understand the Hyperlight Improvement Process (HIP)
mainHyperlight Improvement Proposals (HIPs) are a standardized development process used to communicate intent and maintain a historical record of motivations for Hyperlight enhancements. The process is modeled after the Kubernetes Enhancement Proposal (KEP) process but is scaled to fit the Hyperlight community.
When to use a HIP
A HIP is not required for all changes. You should only propose a HIP for significantly impacting work, such as:
- Large refactorings
- Significant feature enhancements
- Breaking API changes
Third Party Library Use in hyperlight-libc
mainThehyperlight-libcpackage utilizes third-party libraries located in thethird_partysubdirectory. Each library includes its ownCOPYRIGHT/LICENSEfile within its respective subdirectory. For a complete list of all third-party dependencies, refer to theNOTICEfile in the root of the repository.Understand Hyperlight snapshot versioning axes
mainHyperlight snapshots use three independent versioning axes to manage evolution. A change to any of these requires a version bump and potentially a compatibility path in the loader:
- Memory blob ABI (
SNAPSHOT_ABI_VERSION): Au32in the config blob. It defines the interface between host and guest, includingOutBActionandVmActionport numbers, buffer stack formats, memory region offsets/sizes (includingHyperlightPEB), and guest function calling conventions. - Snapshot blob encoding (
MT_SNAPSHOT_V1/MT_SNAPSHOT_CURRENT): The on-wire OCI layer format, covering framing, section ordering, alignment, and byte packing. - Config schema (
MT_CONFIG_V1/MT_CONFIG_CURRENT): The JSON structure of the config blob, including field names, types, and required descriptors (e.g.,abi_version,hyperlight_version).
Note:
hyperlight_version(the host'sCARGO_PKG_VERSION) is recorded in the config for diagnostics but does not gate loading.- Memory blob ABI (
Understand Hyperlight core concepts
mainHyperlight is a library designed to be embedded within a Host Application to provide hypervisor-isolated execution. It uses Sandboxes as an abstraction to create, configure, execute, and destroy Micro Virtual Machines that run Guest binaries. This architecture allows for low-latency execution of Workloads by running purpose-fit guest binaries instead of full operating systems.Understand Hyperlight Guest-aided Copy-on-Write (CoW) snapshots
mainHyperlight uses a design where the guest is aware of a read-only snapshot and manages its own Copy-on-Write (CoW) operations to reduce the cost of Stage 2 translation page faults on Type 1 hypervisors.
The guest physical address space is divided into two fundamental regions:
- Snapshot Region: Located at the very bottom of memory. It is a hypervisor-enforced read-only mapping of the base snapshot.
- Scratch Region: Located at the top of memory. A large area of blank, writable pages used for CoW operations and metadata.
When a guest writes to a CoW page in the snapshot region, it must:
- Allocate a fresh page from the scratch region (using a bump allocator).
- Copy the content from the snapshot page to the new scratch page.
- Update the Page Table Entry (PTE) to point to the new scratch page and set it to R/W.
Understand the Hyperlight Architecture
mainHyperlight operates using two primary components that interact in a controlled manner:
- Host library: Responsible for creating the Hyperlight VM (the "sandbox"), configuring vCPUs, virtual registers, and VM memory, loading the guest binary, and managing function calls. It marshals calls to "guest functions" inside the VM and dispatches "host functions" (callbacks) from the guest back into the host.
- Guest binary: Code running inside the sandbox that dispatches calls from the host to specific guest functions and marshals calls to host functions.