BoxliteRuntime
The main entry point for creating and managing Boxes. Holds all runtime state protected by a singleRwLock.
Source: boxlite/src/runtime/
Key responsibilities:
- Box lifecycle management (create, list, get, remove)
- Image management (pull, cache)
- Runtime-wide metrics collection
- Filesystem layout management
LiteBox
Individual Box handle providing execution capabilities. Supports lazy initialization — heavy work ( image pulling, Box startup) is deferred until first use. Source:boxlite/src/litebox/
Key responsibilities:
- Command execution (
exec) - Metrics collection
- Graceful shutdown
ShimController
Universal subprocess-based Box controller. Spawnsboxlite-shim binary in a subprocess to isolate
Box process takeover from the host application.
Source: boxlite/src/vmm/controller/shim.rs, boxlite/src/bin/shim.rs
Why subprocess isolation:
- libkrun performs process takeover (
krun_start_enternever returns) - Subprocess ensures host application continues running
- Clean process tree management
- Enables jailer to sandbox the shim process
Portal (Host-Guest Communication)
gRPC-based communication layer between host and guest. Components:GuestSession: High-level facade for service interfacesConnection: Lazy gRPC channel management- Service interfaces:
GuestInterface,ContainerInterface,ExecutionInterface
Transport Flow
Protocol Definition
Defined inboxlite-shared/proto/boxlite/v1/service.proto:
Initialization Sequence
Guest Agent
Runs inside the Box, receives commands from host via gRPC. Source:guest/ (crate: boxlite-guest)
Services:
Guest: Environment initialization (mounts, rootfs, network)Container: OCI container lifecycle management (via libcontainer)Execution: Command execution with streaming I/O
container/: OCI container lifecycle using libcontainerstorage/: Filesystem mounts and overlayfs managementnetwork.rs: Virtual NIC configuration and DHCP
VMM Abstraction
BoxLite uses a pluggable VMM (Virtual Machine Monitor) architecture for Box execution. Location:boxlite/src/vmm/
VMM Trait
VmmInstance
Represents a configured Box ready to execute:libkrun (Krun VMM)
Current production VMM implementation using libkrun hypervisor. Features:- Hardware virtualization (macOS Hypervisor.framework, Linux KVM)
- virtio-fs for filesystem sharing
- virtio-blk for disk images
- vsock for host-guest communication
- Process takeover model (
krun_start_enter)
Adding New VMM Implementations
To add a new VMM implementation:Metrics System
BoxLite provides comprehensive metrics at runtime and per-Box levels. Location:boxlite/src/metrics/
Architecture
Design Principles
- Lock-free: Uses
AtomicU64for concurrent updates without synchronization - Low overhead: Metrics collection does not impact Box performance
- Hierarchical: Runtime-wide aggregates plus per-Box details