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 and am example of a simple guest application using the Hyperlight guest library in also written in Rust.
Host
use ;
use ;
use ;
Guest
extern crate alloc;
use ToString;
use Vec;
use FunctionCall;
use ;
use ErrorCode;
use get_flatbuffer_result_from_int;
use ;
use GuestFunctionDefinition;
use register_function;
use ;
pub extern "C"
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 - This is the Rust Hyperlight guest library.
- src/hyperlight_guest_capi - This is the C compatible wrapper for the Hyperlight guest library.
-
Hyperlight Common (functionality used by both the host and the guest)
-
Test Guest Applications:
- src/tests/rust_guests - This directory contains two 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 build int Rust.
Try it yourself!
You can run Hyperlight on:
- Linux with KVM.
- Windows with Windows Hypervisor Platform (WHP).
- Windows Subsystem for Linux 2 (WSL2) 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.78.0 or later. Also, install the
x86_64-pc-windows-msvc
andx86_64-unknown-none
targets withrustup target add <target>
for each; these are needed to build the test guest binaries. (Note: install both targets on either Linux or Windows: Hyperlight can load ELF or PE files on either OS, and the tests/examples are built for both). - just.
cargo install just
. - 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 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 groups that owns the 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).
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.
More Information
For more information, please refer to our compilation of documents in the docs/
directory.
Code of Conduct
See the Code of Conduct.