Run WebAssembly components and modules inside lightweight, hypervisor-isolated micro VMs.
Part of Hyperlight, a Cloud Native Computing Foundation sandbox project.
Status: Hyperlight and Hyperlight Wasm are pre-1.0. The API may change between releases, and upgrading may require code changes.
Hyperlight Wasm embeds Wasmtime inside a Hyperlight micro VM so you can run untrusted or third-party WebAssembly code with hardware-backed isolation, millisecond startup, and microsecond-scale function calls. You embed it as a library in your application, precompile your WebAssembly component or module, and call guest functions across the VM boundary.
- Runs ahead-of-time compiled WebAssembly Component Model (Preview 2) components and core modules on Wasmtime inside a Hyperlight micro VM
- Runs with no guest kernel or OS in the VM
- Host and guest communicate through WIT-generated component bindings or typed function calls
- Sandboxed by default with no access to the host filesystem, network, or environment unless exposed through host functions
- Snapshot and restore support resets VM state between calls to reuse sandboxes
While WebAssembly on its own provides a strong software sandbox, running Wasmtime inside a Hyperlight micro VM adds a hardware-enforced hypervisor boundary for defense in depth. Even if a guest exploits a vulnerability in the WebAssembly runtime to gain arbitrary code execution, it remains confined to the VM. Use it for untrusted WebAssembly workloads that need both low latency and VM-level isolation. For a deeper dive, see the WasmCon talk.
Define the host and guest interface in WIT (greeter.wit):
package example:greeter;
interface host {
prefix: func() -> string;
}
interface greeter {
greet: func(name: string) -> string;
}
world greeter-world {
import host;
export greeter;
}Guest (Rust component) implements the exported interface and calls the host import:
impl Guest for Component {
fn greet(name: String) -> String {
let prefix = host::prefix();
format!("{prefix} {name}!")
}
}Build the guest runtime for that WIT world and precompile the component:
WIT_WORLD=/path/to/greeter.wit cargo build -p hyperlight-wasm
cargo run -p hyperlight-wasm-aot compile --component greeter.wasm greeter.aotHost (Rust) generates bindings directly from the WIT file, registers the host implementation, loads the component, and calls it:
mod bindings {
hyperlight_component_macro::host_bindgen!(wit: "greeter.wit");
}
let mut proto = SandboxBuilder::new().build()?;
let rt = bindings::register_host_functions(&mut proto, state)?;
let sb = proto.load_runtime()?.load_module("greeter.aot")?;
let mut wrapped = bindings::GreeterWorldSandbox { sb, rt };
let greeter = bindings::example::greeter::GreeterWorldExports::greeter(&mut wrapped);
let greeting = greeter.greet("World".to_string())?;
println!("{greeting}"); // "Hello World!"Guest state persists across calls. Use snapshot() and restore() on LoadedWasmSandbox to save and reset VM memory between calls.
See docs/component-model.md for full Component Model configuration (multi-world packages, macro debugging, and binary-encoded WIT), RustDev.md for core module usage and the sandbox lifecycle, and src/hyperlight_wasm/examples for runnable examples.
Preview bindings are available for C and .NET. Both load a guest runtime built for the component's world from a file.
- src/hyperlight_wasm_capi: C API with header
include/hyperlight_wasm.h - dotnet: .NET packages (
Hyperlight.WasmandHyperlight.Wasm.Build) with C# bindings generated from WIT
Skip local setup with a GitHub Codespace:
All platforms require:
- Rust 1.94 (matches
rust-toolchain.toml) - just 1.5.0 or later (
cargo install just). Avoid package managers that install older versions. - Git
Install the pinned WebAssembly and Hyperlight CLI tools (wasm-tools, cargo-component, wit-bindgen, and cargo-hyperlight) with:
just ensure-toolsPlatform-specific setup:
- Linux (KVM): install
build-essential, confirm KVM is available (sudo apt install cpu-checker && kvm-ok), and add your user to thekvmgroup (sudo adduser $USER kvm). - Linux (MSHV): requires a kernel with
/dev/mshvenabled. - Windows (WHP): install PowerShell and enable Windows Hypervisor Platform:
Enable-WindowsOptionalFeature -Online -FeatureName HyperVisorPlatform
- macOS (HVF): install Xcode Command Line Tools (
xcode-select --install) and LLVM (brew install llvm).
Build the Rust library:
just buildBuild the example WebAssembly modules and components used by tests and examples:
just build-examplesjust build-wasm-examples uses wasi-sdk from WASI_SDK_PATH or /opt/wasi-sdk, and downloads it into target if not found.
Run the test suite and try an example:
just test
cargo run --example helloworld| Host OS | Architecture | Hypervisor |
|---|---|---|
| Linux | x86-64 | KVM, MSHV |
| Linux | AArch64 | KVM |
| Windows | x86-64 | WHP |
| Windows | AArch64 | WHP |
| macOS | AArch64 | HVF |
| Directory | Description |
|---|---|
| src/hyperlight_wasm | Host library for creating and managing Wasm micro VM sandboxes |
| src/hyperlight_wasm_runtime | Guest binary embedding Wasmtime inside a Hyperlight micro VM |
| src/hyperlight_wasm_aot | CLI tool for precompiling Wasm modules and components to .aot files |
| src/hyperlight_wasm_macro | Procedural macros for generating WIT bindings in the guest runtime |
| src/hyperlight_wasm_capi | C API wrapper around hyperlight-wasm |
| src/hyperlight_wasm_csharp_bindgen | Native library that generates C# host bindings from WIT |
| dotnet | .NET runtime and build packages with C# bindings generated from WIT |
| src/examples_common | Shared helpers for host examples |
| src/tests | C and Rust guest Wasm modules and components for tests and examples |
| docs | Guides for Component Model configuration, observability, and debugging Wasm modules |
- hyperlight: Lightweight VMM for running untrusted code in micro VMs
- cargo-hyperlight: Cargo subcommand for building and scaffolding Hyperlight guests
- hyperlight-js: Run JavaScript inside Hyperlight micro VMs
- hyperlight-sandbox: Multi-backend sandboxing framework for running untrusted code with controlled host capabilities, with Python, .NET, and Rust SDKs
- hyperlight-unikraft: Run Linux applications (Python, Node.js, Go, Rust, C/C++) on Hyperlight micro VMs using Unikraft as the guest kernel
See CONTRIBUTING.md.
- Meetings: Mondays at 09:00 PST/PDT (convert to your time). Agenda and join info in the Community Meeting Notes. See the calendar at https://zoom-lfx.platform.linuxfoundation.org/meetings/hyperlight?view=month
- Slack: #hyperlight on CNCF Slack (join here).
- Docs: RustDev.md and docs/
- Code of Conduct: Microsoft Open Source Code of Conduct