Note: Hyperlight is a nascent project with an evolving API and no guaranteed support. Assistance is provided on a best-effort basis by the developers.
Overview
Hyperlight is a library for creating micro virtual machines — or sandboxes — specifically optimized for securely running untrusted code with minimal impact. It supports both Windows and Linux, utilizing Windows Hypervisor Platform on Windows, and either Microsoft Hypervisor (mshv) or KVM on Linux.
These micro VMs operate without a kernel or operating system, keeping overhead low. Instead, guests are built specifically for Hyperlight using the Hyperlight Guest library, which provides a controlled set of APIs that facilitate interaction between host and guest:
- The host can call functions implemented and exposed by the guest (known as guest functions).
- Once running, the guest can call functions implemented and exposed by the host (known as host functions).
By default, Hyperlight restricts guest access to a minimal API. The only host function available by default allows the guest to print messages, which are displayed on the host console or redirected to stdout, as configured. Hosts can choose to expose additional host functions, expanding the guest’s capabilities as needed.
Below is an example demonstrating the use of the Hyperlight host library in Rust to execute a simple guest application. It is followed by an example of a simple guest application using the Hyperlight guest library, also written in Rust.
Host
use thread;
use ;
Guest
extern crate alloc;
use ToString;
use Vec;
use FunctionCall;
use ;
use ErrorCode;
use get_flatbuffer_result;
use ;
use GuestFunctionDefinition;
use register_function;
use call_host_function;
pub extern "C"
Note: Guest applications require a specific build configuration. Create a .cargo/config.toml
file in your guest project with the following content:
[]
= "x86_64-unknown-none"
[]
= [
"-C",
"code-model=small",
"-C",
"link-args=-e entrypoint",
]
= "rust-lld"
[]
= "abort"
[]
= "abort"
For additional examples of using the Hyperlight host Rust library, see the ./src/hyperlight_host/examples directory.
For examples of guest applications, see the ./src/tests/c_guests directory for C guests and the ./src/tests/rust_guests directory for Rust guests.
Note: Hyperlight guests can be written using the Hyperlight Rust or C Guest libraries.
Repository Structure
-
Hyperlight Host Libraries (i.e., the ones that create and manage the VMs)
- src/hyperlight_host - This is the Rust Hyperlight host library.
-
Hyperlight Guest Libraries (i.e., the ones to make it easier to create guests that run inside the VMs)
- src/hyperlight_guest - The core Rust library for Hyperlight guests. It provides only the essential building blocks for interacting with the host environment, including the VM exit mechanism (
outb
), abstractions for calling host functions and receiving return values, and the input/output stacks used for guest-host communication. - src/hyperlight_guest_bin - An extension to the core Rust library for Hyperlight guests. It contains more opinionated components (e.g., panic handler, heap initialization, musl-specific imports, logging, and exception handling).
- src/hyperlight_guest_capi - A C-compatible wrapper around
hyperlight_guest_bin
, exposing its core functionality for use in C programs and other languages via FFI.
- src/hyperlight_guest - The core Rust library for Hyperlight guests. It provides only the essential building blocks for interacting with the host environment, including the VM exit mechanism (
-
Hyperlight Common (functionality used by both the host and the guest)
-
Test Guest Applications:
- src/tests/rust_guests - This directory contains three Hyperlight Guest programs written in Rust, which are intended to be launched within partitions as "guests".
- src/tests/c_guests - This directory contains two Hyperlight Guest programs written in C, which are intended to be launched within partitions as "guests".
-
Tests:
- src/hyperlight-testing - Shared testing code for Hyperlight projects built in Rust.
Try it yourself!
You can run Hyperlight on:
- Linux with KVM.
- Windows with Windows Hypervisor Platform (WHP). - Note that you need Windows 11 / Windows Server 2022 or later to use hyperlight, if you are running on earlier versions of Windows then you should consider using our devcontainer on GitHub codespaces or WSL2.
- Windows Subsystem for Linux 2 (see instructions here for Windows client and here for Windows Server) with KVM.
- Azure Linux with mshv (note that you need mshv to be installed to use Hyperlight)
After having an environment with a hypervisor setup, running the example has the following pre-requisites:
- On Linux or WSL, you'll most likely need build essential. For Ubuntu, run
sudo apt install build-essential
. For Azure Linux, runsudo dnf install build-essential
. - Rust. Install toolchain v1.86 or later.
- just.
cargo install just
On Windows you also need pwsh. - clang and LLVM.
-
On Ubuntu, run:
-
On Windows, see this.
-
On Azure Linux, run:
||
-
Then, we are ready to build and run the example:
If all worked as expected, you should see the following message in your console:
Hello, World! I am executing inside of a VM :)
If you get the error Error: NoHypervisorFound
and KVM or mshv is set up then this may be a permissions issue. In bash,
you can use ls -l /dev/kvm
or ls -l /dev/mshv
to check which group owns that device and then groups
to make sure
your user is a member of that group.
For more details on how to verify that KVM is correctly installed and permissions are correct, follow the guide here.
Or you can use a codespace
Contributing to Hyperlight
If you are interested in contributing to Hyperlight, running the entire test-suite is a good way to get started. To do so, on your console, run the following commands:
Also , please review the CONTRIBUTING.md file for more information on how to contribute to Hyperlight.
Note: For general Hyperlight development, you may also need flatc (Flatbuffer compiler): for instructions, see here. Copyright © contributors to Hyperlight, established as Hyperlight a Series of LF Projects, LLC.
Join our Community Meetings
This project holds fortnightly community meetings to discuss the project's progress, roadmap, and any other topics of interest. The meetings are open to everyone, and we encourage you to join us.
- When: Every other Wednesday 09:00 (PST/PDT) Convert to your local time
- Where: Zoom! - Agenda and information on how to join can be found in the Hyperlight Community Meeting Notes. Please log into hackmd to edit!
Chat with us on the CNCF Slack
The Hyperlight project Slack is hosted in the CNCF Slack #hyperlight. To join the Slack, join the CNCF Slack, and join the #hyperlight channel.
More Information
For more information, please refer to our compilation of documents in the docs/
directory.
Code of Conduct
See the CNCF Code of Conduct.