# danieltangnes/hyperlight architecture

> Architecture diagram of the GitHub repository danieltangnes/hyperlight, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danieltangnes/hyperlight
- Repository: https://github.com/danieltangnes/hyperlight

## Overview

Hyperlight is a Rust library for running untrusted, purpose-built guest binaries in hypervisor-isolated micro VMs. The main workflow is an embedding host application building a sandbox from a guest binary, then making typed calls across the host/guest boundary; the guest can call registered host functions. The host manages VM execution, memory, and snapshots. Shared virtqueues and message codecs support transport, while guest tracing is relayed to host-side trace handling. The README documents the major capabilities; several subsystem links below are documented there because their implementation was not sampled.

Main entry points: [`src/hyperlight_host/src/sandbox/initialized.rs`](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/initialized.rs) (Sandbox calls), [`src/hyperlight_guest_bin/src/lib.rs`](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest_bin/src/lib.rs) (Default guest runtime), [`src/hyperlight_host/src/sandbox/builder.rs`](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/builder.rs) (Sandbox builder), [`src/hyperlight_host/src/mem/mgr.rs`](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/mem/mgr.rs) (Guest memory manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host sandbox"]
  node_builder["Sandbox builder<br/>[builder.rs]"]
  node_sandbox["Sandbox calls<br/>[initialized.rs]"]
  node_host_functions["Host functions<br/>[host_funcs.rs]"]
  node_snapshot["Snapshot restore<br/>[mod.rs]"]
end

subgraph group_vm["VM and memory"]
  node_hypervisor["Hypervisor backends<br/>[mod.rs]"]
  node_memory_manager["Guest memory manager<br/>[mgr.rs]"]
  node_memory_regions["Memory regions<br/>[memory_region.rs]"]
  node_shared_memory["Shared memory<br/>[shared_mem.rs]"]
end

subgraph group_guest["Guest runtime"]
  node_guest_runtime["Default guest runtime<br/>[lib.rs]"]
  node_guest_primitives["Guest primitives<br/>[context.rs]"]
end

subgraph group_transport["Shared transport"]
  node_common_types["Call message types<br/>[function_call.rs]"]
  node_virtqueue["Virtqueue API<br/>[mod.rs]"]
end

subgraph group_extensions["Bindings and tracing"]
  node_guest_macros["Guest function macros<br/>[lib.rs]"]
  node_component_bindings["WIT bindings<br/>[emit.rs]"]
  node_guest_tracing["Guest tracing<br/>[lib.rs]"]
  node_host_trace["Host trace handling<br/>[context.rs]"]
end

node_host_app(("Host application"))
node_guest_binary["Guest binary"]

node_host_app -->|"builds sandbox"| node_builder
node_builder -->|"loads guest"| node_guest_binary
node_builder -.->|"creates"| node_sandbox
node_sandbox -.->|"runs guest"| node_hypervisor
node_sandbox -->|"dispatches calls"| node_memory_manager
node_sandbox -->|"registers functions"| node_host_functions
node_sandbox -->|"snapshots state"| node_snapshot
node_memory_manager -->|"manages regions"| node_memory_regions
node_memory_manager -->|"uses shared memory"| node_shared_memory
node_guest_binary -->|"runs with"| node_guest_runtime
node_guest_runtime -.->|"uses transport"| node_guest_primitives
node_guest_primitives -->|"submits messages"| node_virtqueue
node_guest_primitives -.->|"encodes calls"| node_common_types
node_sandbox -->|"exchanges typed calls"| node_common_types
node_guest_macros -->|"exposes functions"| node_guest_runtime
node_component_bindings -.->|"generates bindings"| node_guest_runtime
node_guest_runtime -.->|"emits trace events"| node_guest_tracing
node_host_trace -.->|"receives trace data"| node_guest_tracing

click node_builder "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/builder.rs"
click node_sandbox "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/initialized.rs"
click node_host_functions "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/host_funcs.rs"
click node_snapshot "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/snapshot/mod.rs"
click node_hypervisor "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs"
click node_memory_manager "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/mem/mgr.rs"
click node_memory_regions "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/mem/memory_region.rs"
click node_shared_memory "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/mem/shared_mem.rs"
click node_guest_runtime "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest_bin/src/lib.rs"
click node_guest_primitives "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest/src/transport/context.rs"
click node_common_types "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_common/src/flatbuffer_wrappers/function_call.rs"
click node_virtqueue "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_common/src/virtq/mod.rs"
click node_guest_macros "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest_macro/src/lib.rs"
click node_component_bindings "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_component_util/src/emit.rs"
click node_guest_tracing "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest_tracing/src/lib.rs"
click node_host_trace "https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/trace/context.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_builder,node_sandbox,node_host_functions,node_snapshot toneBlue
class node_hypervisor,node_memory_manager,node_memory_regions,node_shared_memory toneAmber
class node_guest_runtime,node_guest_primitives toneMint
class node_common_types,node_virtqueue toneRose
class node_guest_macros,node_component_bindings,node_guest_tracing,node_host_trace,node_host_app,node_guest_binary toneIndigo
```

## Components

### Host sandbox

- [Sandbox builder](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/builder.rs): `src/hyperlight_host/src/sandbox/builder.rs`
- [Sandbox calls](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/initialized.rs): `src/hyperlight_host/src/sandbox/initialized.rs`
- [Host functions](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/host_funcs.rs): `src/hyperlight_host/src/sandbox/host_funcs.rs`
- [Snapshot restore](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/snapshot/mod.rs): `src/hyperlight_host/src/sandbox/snapshot/mod.rs`

### VM and memory

- [Hypervisor backends](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs): `src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs`
- [Guest memory manager](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/mem/mgr.rs): `src/hyperlight_host/src/mem/mgr.rs`
- [Memory regions](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/mem/memory_region.rs): `src/hyperlight_host/src/mem/memory_region.rs`
- [Shared memory](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/mem/shared_mem.rs): `src/hyperlight_host/src/mem/shared_mem.rs`

### Guest runtime

- [Default guest runtime](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest_bin/src/lib.rs): `src/hyperlight_guest_bin/src/lib.rs`
- [Guest primitives](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest/src/transport/context.rs): `src/hyperlight_guest/src/transport/context.rs`

### Shared transport

- [Call message types](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_common/src/flatbuffer_wrappers/function_call.rs): `src/hyperlight_common/src/flatbuffer_wrappers/function_call.rs`
- [Virtqueue API](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_common/src/virtq/mod.rs): `src/hyperlight_common/src/virtq/mod.rs`

### Bindings and tracing

- [Guest function macros](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest_macro/src/lib.rs): `src/hyperlight_guest_macro/src/lib.rs`
- [WIT bindings](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_component_util/src/emit.rs): `src/hyperlight_component_util/src/emit.rs`
- [Guest tracing](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_guest_tracing/src/lib.rs): `src/hyperlight_guest_tracing/src/lib.rs`
- [Host trace handling](https://github.com/danieltangnes/hyperlight/blob/main/src/hyperlight_host/src/sandbox/trace/context.rs): `src/hyperlight_host/src/sandbox/trace/context.rs`

### Other components

- **Host application**
- **Guest binary**

## Connections

- Host application → Sandbox builder: builds sandbox (evidence: `README.md`)
- Sandbox builder → Guest binary: loads guest (evidence: `README.md`)
- Sandbox builder → Sandbox calls: creates
- Sandbox calls → Hypervisor backends: runs guest (evidence: `src/hyperlight_host/src/sandbox/initialized.rs`)
- Sandbox calls → Guest memory manager: dispatches calls (evidence: `src/hyperlight_host/src/sandbox/initialized.rs`)
- Sandbox calls → Host functions: registers functions (evidence: `README.md`)
- Sandbox calls → Snapshot restore: snapshots state (evidence: `README.md`)
- Guest memory manager → Memory regions: manages regions (evidence: `src/hyperlight_host/src/mem/mgr.rs`)
- Guest memory manager → Shared memory: uses shared memory (evidence: `src/hyperlight_host/src/mem/mgr.rs`)
- Guest binary → Default guest runtime: runs with (evidence: `README.md`)
- Default guest runtime → Guest primitives: uses transport
- Guest primitives → Virtqueue API: submits messages (evidence: `src/hyperlight_guest/src/transport/context.rs`)
- Guest primitives → Call message types: encodes calls
- Sandbox calls → Call message types: exchanges typed calls (evidence: `README.md`)
- Guest function macros → Default guest runtime: exposes functions (evidence: `README.md`)
- WIT bindings → Default guest runtime: generates bindings
- Default guest runtime → Guest tracing: emits trace events
- Host trace handling → Guest tracing: receives trace data
