Skip to content

Commit fd5716f

Browse files
authored
Update README (#1359)
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 49d9946 commit fd5716f

5 files changed

Lines changed: 364 additions & 270 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,4 @@ hyperlight_guest.h
473473
.gdbinit
474474
trace/*
475475
.gdbguest
476+
.copilot-reviews/

README.md

Lines changed: 86 additions & 239 deletions
Original file line numberDiff line numberDiff line change
@@ -1,277 +1,124 @@
11
<div align="center">
22
<h1>Hyperlight</h1>
33
<img src="https://raw.githubusercontent.com/hyperlight-dev/hyperlight/refs/heads/main/docs/assets/hyperlight-logo.png" width="150px" alt="hyperlight logo"/>
4-
<p><strong>Hyperlight is a lightweight Virtual Machine Manager (VMM) designed to be embedded within applications. It enables safe execution of untrusted code within <i>micro virtual machines</i> with very low latency and minimal overhead.</strong> <br> We are a <a href="https://cncf.io/">Cloud Native Computing Foundation</a> sandbox project. </p>
4+
<p>
5+
<strong>A lightweight VMM for running untrusted code in micro VMs with minimal overhead.</strong><br>
6+
A <a href="https://www.cncf.io/projects/hyperlight/">Cloud Native Computing Foundation</a> sandbox project.
7+
</p>
58
</div>
69

7-
> Note: Hyperlight is a nascent project with an evolving API and no guaranteed support. Assistance is provided on a
8-
> best-effort basis by the developers.
10+
> **Status:** Hyperlight is pre-1.0. The API may change between releases, and upgrading will sometimes require code changes.
911
10-
---
11-
12-
## Overview
13-
14-
Hyperlight is a library for creating _micro virtual machines_ — or _sandboxes_ — specifically optimized for securely
15-
running untrusted code with minimal impact. It supports both Windows and Linux,
16-
utilizing [Windows Hypervisor Platform](https://docs.microsoft.com/en-us/virtualization/api/#windows-hypervisor-platform)
17-
on Windows, and either Microsoft Hypervisor (mshv) or [KVM](https://linux-kvm.org/page/Main_Page) on Linux.
18-
19-
These micro VMs operate without a kernel or operating system, keeping overhead low. Instead, guests are built
20-
specifically for Hyperlight using the Hyperlight Guest library, which provides a controlled set of APIs that facilitate
21-
interaction between host and guest:
12+
Hyperlight lets you safely run untrusted code inside hypervisor-isolated micro VMs that spin up in milliseconds, with guest function calls completing in microseconds. You embed it as a library in your Rust application, hand it a guest binary, and call functions across the VM boundary as naturally as calling a local function. To minimize startup time and memory footprint, there's no guest kernel or OS. Guests are purpose-built using the Hyperlight guest library.
2213

23-
- The host can call functions implemented and exposed by the guest (known as _guest functions_).
24-
- Once running, the guest can call functions implemented and exposed by the host (known as _host functions_).
14+
- Supports [KVM](https://linux-kvm.org/page/Main_Page), [MSHV](https://github.com/rust-vmm/mshv), and [Windows Hypervisor Platform](https://docs.microsoft.com/en-us/virtualization/api/#windows-hypervisor-platform)
15+
- No kernel or OS in the VM. Guests are regular ELF binaries written in `no_std` Rust or C
16+
- Host and guest communicate through typed function calls
17+
- Guests are sandboxed by default with no access to the host filesystem, network, etc.
2518

26-
By default, Hyperlight restricts guest access to a minimal API. The only _host function_ available by default allows the
27-
guest to print messages, which are displayed on the host console or redirected to stdout, as configured. Hosts can
28-
choose to expose additional host functions, expanding the guest’s capabilities as needed.
19+
## Example
2920

30-
Below is an example demonstrating the use of the Hyperlight host library in Rust to execute a simple guest application.
31-
It is followed by an example of a simple guest application using the Hyperlight guest library, also written in Rust.
32-
33-
### Host
21+
**Host** - create a sandbox, register a host function, and call into the guest:
3422

3523
```rust
36-
use std::thread;
37-
38-
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
39-
40-
fn main() -> hyperlight_host::Result<()> {
41-
// Create an uninitialized sandbox with a guest binary
42-
let mut uninitialized_sandbox = UninitializedSandbox::new(
43-
hyperlight_host::GuestBinary::FilePath("path/to/your/guest/binary".to_string()),
44-
None // default configuration
45-
)?;
46-
47-
// Registering a host function makes it available to be called by the guest
48-
uninitialized_sandbox.register("Sleep5Secs", || {
49-
thread::sleep(std::time::Duration::from_secs(5));
50-
Ok(())
51-
})?;
52-
// Note: This function is unused by the guest code below, it's just here for demonstration purposes
53-
54-
// Initialize sandbox to be able to call host functions
55-
let mut multi_use_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve()?;
56-
57-
// Call a function in the guest
58-
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
59-
// in order to call a function it first must be defined in the guest and exposed so that
60-
// the host can call it
61-
multi_use_sandbox.call::<i32>(
62-
"PrintOutput",
63-
message,
64-
)?;
65-
66-
Ok(())
67-
}
68-
```
24+
// Create an uninitialized sandbox by giving it the path to a guest binary.
25+
// Allocates memory but does not yet run a VM.
26+
let mut sandbox = UninitializedSandbox::new(GuestBinary::FilePath(guest_path), None)?;
6927

70-
### Guest
28+
// Register a host function that the guest can call. In a real app this
29+
// might query a database, read a config, or call an external API.
30+
// By default, guests can only print to the host.
31+
sandbox.register("GetWeekday", || Ok("Monday".to_string()))?;
7132

72-
First, create a `Cargo.toml` with the required dependencies:
33+
// Initialize the sandbox. Starts the VM and runs guest setup code.
34+
let mut sandbox: MultiUseSandbox = sandbox.evolve()?;
7335

74-
```toml
75-
[package]
76-
name = "my-hyperlight-guest"
77-
version = "0.1.0"
78-
edition = "2024"
79-
80-
[dependencies]
81-
hyperlight-guest = "0.12"
82-
hyperlight-guest-bin = "0.12"
83-
hyperlight-common = { version = "0.12", default-features = false }
36+
// Call a function inside the VM
37+
let greeting: String = sandbox.call("SayHello", "World".to_string())?;
38+
println!("{greeting}"); // "Hello, World! Today is Monday."
8439
```
8540

86-
> **Important:** The `hyperlight-common` crate must have `default-features = false` to avoid pulling in
87-
> the standard library, which conflicts with the `no_std` requirement for guests.
41+
Guest state persists across calls. Use `snapshot()` and `restore()` to save and reset VM memory. This avoids recreating the VM while ensuring each call starts from a clean state.
8842

89-
Then, create `src/main.rs`:
43+
**Guest** (Rust) - declare host functions and expose guest functions with simple macros. Guests can also be [written in C](./src/hyperlight_guest_capi).
9044

9145
```rust
92-
#![no_std]
93-
#![no_main]
94-
extern crate alloc;
95-
extern crate hyperlight_guest_bin;
96-
97-
use alloc::vec::Vec;
98-
use alloc::string::String;
99-
use hyperlight_common::flatbuffer_wrappers::function_call::FunctionCall;
100-
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
101-
102-
use hyperlight_guest::bail;
103-
use hyperlight_guest::error::Result;
104-
use hyperlight_guest_bin::{guest_function, host_function};
105-
106-
#[host_function("HostPrint")]
107-
fn host_print(message: String) -> Result<i32>;
108-
109-
#[guest_function("PrintOutput")]
110-
fn print_output(message: String) -> Result<i32> {
111-
let result = host_print(message)?;
112-
Ok(result)
113-
}
114-
115-
#[no_mangle]
116-
pub extern "C" fn hyperlight_main() {
117-
// any initialization code goes here
118-
}
46+
#[host_function("GetWeekday")]
47+
fn get_weekday() -> Result<String>;
11948

120-
#[no_mangle]
121-
pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> {
122-
let function_name = function_call.function_name;
123-
bail!(ErrorCode::GuestFunctionNotFound => "{function_name}");
49+
#[guest_function("SayHello")]
50+
fn say_hello(name: String) -> Result<String> {
51+
let weekday = get_weekday()?;
52+
Ok(format!("Hello, {name}! Today is {weekday}."))
12453
}
12554
```
12655

127-
Build the guest using [cargo-hyperlight](https://github.com/hyperlight-dev/cargo-hyperlight):
56+
To get started, see the [Getting Started](./docs/getting-started.md) guide. For more details on writing guests, see [How to build a Hyperlight guest binary](./docs/how-to-build-a-hyperlight-guest-binary.md).
12857

129-
```sh
130-
cargo install --locked cargo-hyperlight
131-
cargo hyperlight build
132-
```
133-
134-
> **Note:** You must use `cargo hyperlight build` instead of the regular `cargo build` command.
135-
> The `cargo-hyperlight` tool sets up the required custom target, sysroot, and compiler flags
136-
> that are necessary for building Hyperlight guests.
58+
## When to use Hyperlight
13759

138-
For additional examples of using the Hyperlight host Rust library, see
139-
the [./src/hyperlight_host/examples](./src/hyperlight_host/examples) directory.
60+
Hyperlight is a good fit when you need to:
14061

141-
For examples of guest applications, see the [./src/tests/c_guests](./src/tests/c_guests) directory for C guests and
142-
the [./src/tests/rust_guests](./src/tests/rust_guests) directory for Rust guests.
62+
- Run untrusted or third-party code with hypervisor-level isolation
63+
- Create and tear down sandboxes in milliseconds
64+
- Make guest function calls in microseconds
65+
- Embed sandboxed execution directly in your application
66+
- Build functions-as-a-service with hypervisor-level isolation
67+
- Reuse sandboxes efficiently with snapshot and restore
14368

144-
> Note: Hyperlight guests can be written using the Hyperlight Rust or C Guest libraries.
69+
Hyperlight is *not* designed for:
14570

146-
## Repository Structure
71+
- General-purpose virtualization (use a full VMM instead)
72+
- Running full-blown Linux guest workloads that need syscalls, networking, or filesystem access
14773

148-
- Hyperlight Host Libraries (i.e., the ones that create and manage the VMs)
149-
- [src/hyperlight_host](./src/hyperlight_host) - This is the Rust Hyperlight host library.
74+
## Getting started
15075

151-
- Hyperlight Guest Libraries (i.e., the ones to make it easier to create guests that run inside the VMs)
152-
- [src/hyperlight_guest](./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.
153-
- [src/hyperlight_guest_bin](./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).
154-
- [src/hyperlight_guest_capi](./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.
76+
See [docs/getting-started.md](./docs/getting-started.md) for detailed prerequisites and platform-specific setup for:
77+
- **Running** Hyperlight
78+
- **Building guests**
15579

156-
- Hyperlight Common (functionality used by both the host and the guest)
157-
- [src/hyperlight_common](./src/hyperlight_common)
158-
159-
- Test Guest Applications:
160-
- [src/tests/rust_guests](./src/tests/rust_guests) - This directory contains three Hyperlight Guest programs written
161-
in Rust, which are intended to be launched within partitions as "guests".
162-
- [src/tests/c_guests](./src/tests/c_guests) - This directory contains two Hyperlight Guest programs written in C,
163-
which are intended to be launched within partitions as "guests".
164-
165-
- Tests:
166-
- [src/hyperlight-testing](./src/hyperlight_testing) - Shared testing code for Hyperlight projects built in Rust.
167-
168-
## Try it yourself!
169-
170-
You can run Hyperlight on:
171-
172-
- [Linux with KVM][kvm].
173-
- [Windows with Windows Hypervisor Platform (WHP).][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]((https://codespaces.new/hyperlight-dev/hyperlight)) or WSL2.
174-
- Windows Subsystem for Linux 2 (see instructions [here](https://learn.microsoft.com/en-us/windows/wsl/install) for Windows client and [here](https://learn.microsoft.com/en-us/windows/wsl/install-on-server) for Windows Server) with KVM.
175-
- Azure Linux with mshv (note that you need mshv to be installed to use Hyperlight)
176-
177-
After having an environment with a hypervisor setup, running the example has the following pre-requisites:
178-
179-
1. On Linux or WSL, you'll most likely need build essential. For Ubuntu, run `sudo apt install build-essential`. For
180-
Azure Linux, run `sudo dnf install build-essential`.
181-
2. [Rust](https://www.rust-lang.org/tools/install). Install toolchain v1.89 or later.
182-
3. [just](https://github.com/casey/just). `cargo install just` On Windows you also need [pwsh](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4).
183-
4. [clang and LLVM](https://clang.llvm.org/get_started.html).
184-
- On Ubuntu, run:
185-
186-
```sh
187-
wget https://apt.llvm.org/llvm.sh
188-
chmod +x ./llvm.sh
189-
sudo ./llvm.sh 18 clang clang-tools-extra
190-
sudo ln -s /usr/lib/llvm-18/bin/ld.lld /usr/bin/ld.lld
191-
sudo ln -s /usr/lib/llvm-18/bin/clang /usr/bin/clang
192-
```
193-
194-
- On Windows, see [this](https://learn.microsoft.com/en-us/cpp/build/clang-support-msbuild?view=msvc-170).
195-
196-
- On Azure Linux, run:
197-
198-
```sh
199-
if ! command -v clang > /dev/null 2>&1; then
200-
sudo dnf install clang -y
201-
sudo dnf install clang-tools-extra -y
202-
fi
203-
```
204-
205-
Then, we are ready to build and run the example:
206-
207-
```sh
208-
just build # build the Hyperlight library
209-
just rg # build the rust test guest binaries
210-
cargo run --example hello-world
211-
```
212-
213-
If all worked as expected, you should see the following message in your console:
214-
215-
```text
216-
Hello, World! I am executing inside of a VM :)
217-
```
218-
219-
If you get the error `Error: NoHypervisorFound` and KVM or mshv is set up then this may be a permissions issue. In bash,
220-
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
221-
your user is a member of that group.
222-
223-
For more details on how to verify that KVM is correctly installed and permissions are correct, follow the
224-
guide [here](https://help.ubuntu.com/community/KVM/Installation).
225-
226-
For additional debugging tips, including common build and runtime issues, see the [How to build a Hyperlight guest binary](./docs/how-to-build-a-hyperlight-guest-binary.md) guide.
227-
228-
### Or you can use a codespace
80+
Or skip setup entirely with a codespace:
22981

23082
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/hyperlight-dev/hyperlight)
23183

232-
## Contributing to Hyperlight
233-
234-
If you are interested in contributing to Hyperlight, running the entire test-suite is a good way to get started. To do
235-
so, on your console, run the following commands:
236-
237-
```sh
238-
just guests # build the c and rust test guests
239-
just build # build the Hyperlight library
240-
just test # runs the tests
241-
```
242-
243-
Also , please review the [CONTRIBUTING.md](./CONTRIBUTING.md) file for more information on how to contribute to
244-
Hyperlight.
245-
246-
> Note: For general Hyperlight development, you may also need flatc (Flatbuffer compiler): for instructions,
247-
> see [here](https://github.com/google/flatbuffers).
248-
> Copyright © contributors to Hyperlight, established as Hyperlight a Series of LF Projects, LLC.
249-
250-
## Join our Community Meetings
251-
252-
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.
253-
254-
- **When**: Every other Wednesday 09:00 (PST/PDT) [Convert to your local time](https://dateful.com/convert/pst-pdt-pacific-time?t=09)
255-
- **Where**: Zoom! - Agenda and information on how to join can be found in the [Hyperlight Community Meeting Notes](https://hackmd.io/blCrncfOSEuqSbRVT9KYkg#Agenda). Please log into hackmd to edit!
256-
257-
## Chat with us on the CNCF Slack
258-
259-
The Hyperlight project Slack is hosted in the CNCF Slack #hyperlight. To join the Slack, [join the CNCF Slack](https://www.cncf.io/membership-faq/#how-do-i-join-cncfs-slack), and join the #hyperlight channel.
260-
261-
## More Information
262-
263-
For more information, please refer to our compilation of documents in the [`docs/` directory](./docs/README.md).
264-
265-
## Code of Conduct
266-
267-
See the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).
268-
269-
[wsl2]: https://docs.microsoft.com/en-us/windows/wsl/install
270-
271-
[kvm]: https://help.ubuntu.com/community/KVM/Installation
84+
## Repository Structure
27285

273-
[whp]: https://devblogs.microsoft.com/visualstudio/hyper-v-android-emulator-support/#1-enable-hyper-v-and-the-windows-hypervisor-platform
86+
| Directory | Description |
87+
|---|---|
88+
| [src/hyperlight_host](./src/hyperlight_host) | Host library - creates and manages micro VMs |
89+
| [src/hyperlight_guest](./src/hyperlight_guest) | Core guest library - minimal building blocks for guest-host interaction |
90+
| [src/hyperlight_guest_bin](./src/hyperlight_guest_bin) | Extended guest library - entry point, panic handler, heap, logging, exceptions |
91+
| [src/hyperlight_guest_capi](./src/hyperlight_guest_capi) | C API wrapper around `hyperlight_guest_bin` for use via FFI |
92+
| [src/hyperlight_libc](./src/hyperlight_libc) | C standard library for guests, built from picolibc |
93+
| [src/hyperlight_guest_macro](./src/hyperlight_guest_macro) | Macros for registering guest and host functions |
94+
| [src/hyperlight_guest_tracing](./src/hyperlight_guest_tracing) | Tracing support for guests |
95+
| [src/hyperlight_common](./src/hyperlight_common) | Shared code used by both host and guest |
96+
| [src/hyperlight_component_macro](./src/hyperlight_component_macro) | Proc macros for WIT-based host/guest bindings |
97+
| [src/hyperlight_component_util](./src/hyperlight_component_util) | Shared implementation for WIT binding generation |
98+
| [src/hyperlight_testing](./src/hyperlight_testing) | Shared test utilities |
99+
| [src/schema](./src/schema) | FlatBuffer schema definitions |
100+
| [src/trace_dump](./src/trace_dump) | Tool for dumping and visualizing trace data |
101+
| [src/tests](./src/tests) | Test guest programs (Rust and C) |
102+
103+
## Related Projects
104+
105+
- [cargo-hyperlight](https://github.com/hyperlight-dev/cargo-hyperlight) - Cargo subcommand for building and scaffolding Hyperlight guests
106+
- [hyperlight-wasm](https://github.com/hyperlight-dev/hyperlight-wasm) - Run WebAssembly modules inside Hyperlight micro VMs
107+
- [hyperlight-js](https://github.com/hyperlight-dev/hyperlight-js) - Run JavaScript inside Hyperlight micro VMs
108+
- [hyperlight-sandbox](https://github.com/hyperlight-dev/hyperlight-sandbox) - Multi-backend sandboxing framework for running untrusted code with controlled host capabilities, with Python, .NET, and Rust SDKs
109+
- [hyperlight-unikraft](https://github.com/hyperlight-dev/hyperlight-unikraft) - Run Linux applications (Python, Node.js, Go, Rust, C/C++) on Hyperlight micro VMs using Unikraft as the guest kernel
110+
111+
## Contributing
112+
113+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
114+
115+
## Community
116+
117+
- **Meetings**: Every other Wednesday 09:00 PST/PDT ([convert to your time](https://dateful.com/convert/pst-pdt-pacific-time?t=09)). Agenda and join info in the [Community Meeting Notes](https://hackmd.io/blCrncfOSEuqSbRVT9KYkg#Agenda).
118+
- **Slack**: [#hyperlight](https://cloud-native.slack.com/archives/hyperlight) on CNCF Slack ([join here](https://www.cncf.io/membership-faq/#how-do-i-join-cncfs-slack)).
119+
- **Docs**: [`docs/` directory](./docs/README.md)
120+
- **Code of Conduct**: [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md)
274121

122+
---
275123

276-
## FOSSA Status
277124
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhyperlight-dev%2Fhyperlight.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhyperlight-dev%2Fhyperlight?ref=badge_large)

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This project is composed internally of several components, depicted in the below
2424

2525
## Further reading
2626

27+
* [Getting Started](./getting-started.md)
2728
* [Glossary](./glossary.md)
2829
* [How code gets executed in a VM](./hyperlight-execution-details.md)
2930
* [How to build a Hyperlight guest binary](./how-to-build-a-hyperlight-guest-binary.md)

0 commit comments

Comments
 (0)