How boxlite-ai/boxlite works
Purpose and primary entry points
BoxLite is a Rust micro-VM runtime for persistent OCI-image workloads, exposed as embedded SDKs, a CLI/REST server, and an optional multi-tenant cloud control plane. Core local entry points are the runtime crate at src/boxlite/src/lib.rs, CLI binary at src/cli/src/main.rs, and REST serving commands under src/cli/src/commands/serve/. Language bindings wrap the same native runtime in sdks/python/src/lib.rs, sdks/node/src/lib.rs, sdks/go/runtime.go, and sdks/c/src/lib.rs.
Local runtime orchestration
The runtime coordinates box identity, configuration, persistence, lifecycle, and backend selection. src/boxlite/src/runtime/core.rs and src/boxlite/src/runtime/rt_impl.rs expose runtime operations; src/boxlite/src/litebox/manager.rs owns box lifecycle. A box creation path prepares an OCI-derived root filesystem and disk, launches a VM, then establishes a host-to-guest control channel; stop/restart preserves local state.
VM, guest, and execution boundary
Each box is a VM controlled by the host runtime through the VMM abstraction in src/boxlite/src/vmm/engine.rs and platform-specific libkrun implementation in src/boxlite/src/vmm/krun/engine.rs. Inside the guest, src/guest/src/main.rs starts services; src/guest/src/service/server.rs serves the shared protocol defined by src/shared/proto/boxlite/v1/service.proto. The guest manages OCI-container lifecycle and commands in src/guest/src/container/ and src/guest/src/service/exec/, returning streamed execution state across this boundary.
Isolation, storage, images, and networking
Host-side jailer construction applies OS sandboxing, credentials, cgroups/rlimits, and syscall controls through src/boxlite/src/jailer/builder.rs, src/boxlite/src/jailer/seccomp.rs, and src/boxlite/src/jailer/sandbox/. OCI images are fetched, verified/unpacked, cached, and converted to usable disks by src/boxlite/src/images/manager.rs and src/boxlite/src/images/archive/. Persistent box data uses QCOW2/ext4 and volume layers in src/boxlite/src/disk/, src/boxlite/src/db/, and src/boxlite/src/volumes/. Network forwarding and egress policy integrate through src/boxlite/src/net/gvproxy/.
CLI, SDK, and standalone REST surfaces
The CLI dispatches local or remote lifecycle, exec, image, file, and auth operations from src/cli/src/cli.rs and src/cli/src/commands/. Server mode maps HTTP/WebSocket requests to runtime actions via src/cli/src/commands/serve/handlers/. SDKs present idiomatic APIs but bind to the Rust engine; the C SDK is the FFI foundation for Go, while Python and Node build native extension layers. Remote REST support is also implemented inside the runtime under src/boxlite/src/rest/.
Cloud control plane and fleet runner
The cloud stack separates a TypeScript/NestJS control plane from Go runners that host BoxLite workloads. The API boots at apps/api/src/main.ts; box desired state, jobs, runners, volumes, and adapters are centered in apps/api/src/box/services/box.service.ts, apps/api/src/box/managers/box.manager.ts, and apps/api/src/box/runner-adapter/. Runners start at apps/runner/cmd/runner/main.go, poll/execute work in apps/runner/pkg/runner/v2/, and invoke local BoxLite through apps/runner/pkg/boxlite/. This is the principal control-plane-to-compute trust and scheduling boundary.
Cloud clients, identity, observability, and infrastructure
The dashboard is a React/Vite client rooted at apps/dashboard/src/main.tsx, using generated control-plane clients under apps/libs/api-client/src/. Authentication supports JWT/API-key and runner-specific guards in apps/api/src/auth/; organization and region tenancy are enforced in apps/api/src/organization/ and apps/api/src/region/. Material services indicated by adapters/modules include PostgreSQL/TypeORM, Redis locks and notifications, Kafka audit transport, ClickHouse telemetry, OpenSearch audit storage, S3/CloudWatch observability, PostHog/OpenFeature, OIDC/Dex, and Svix webhooks. AWS/Cloudflare deployment is defined by apps/infra/sst.config.ts; OpenTelemetry collection is a separate Go-based image/service in apps/otel-collector/.
Main entry points: manager.rs Box lifecycle · core.rs Runtime core · main.ts Control-plane API · engine.rs VMM abstraction
Components 22
Local BoxLite
- Runtime core · Coordinates identity, configuration, persistence, lifecycle, and backend selection.
src/boxlite/src/runtime/core.rs - Box lifecycle · Creates, stops, and restarts persistent boxes.
src/boxlite/src/litebox/manager.rs - OCI image pipeline · Fetches, verifies, unpacks, caches, and converts images.
src/boxlite/src/images/manager.rs - Persistent storage · QCOW2/ext4 box state and volume layers.
src/boxlite/src/disk/mod.rs - Host isolation · Applies sandboxing, credentials, limits, and syscall controls.
src/boxlite/src/jailer/builder.rs - VMM abstraction
src/boxlite/src/vmm/engine.rs - libkrun backend
src/boxlite/src/vmm/krun/engine.rs - Network forwarding · Provides forwarding and egress policy.
src/boxlite/src/net/gvproxy/mod.rs
VM Guest
- Shared control protocol · Host-to-guest control and streamed execution contract.
src/shared/proto/boxlite/v1/service.proto - Guest service · Starts guest services and serves the shared protocol.
src/guest/src/service/server.rs - Guest containers · Manages container lifecycle and commands.
src/guest/src/container/mod.rs
Developer Surfaces
- CLI · Dispatches local or remote lifecycle, exec, image, file, and auth operations.
src/cli/src/main.rs - Standalone REST server · Maps server-mode requests to runtime actions.
src/cli/src/commands/serve/handlers/mod.rs - Language SDKs · Python, Node, Go, and C APIs expose the native runtime.
sdks/c/src/lib.rs
Cloud Platform
- Control-plane API · Owns desired state, jobs, runners, volumes, and adapters.
apps/api/src/main.ts - Identity and tenancy · JWT/API-key and runner guards enforce organization and region boundaries.
apps/api/src/auth/auth.module.ts - Cloud data services · PostgreSQL, Redis, Kafka, audit, telemetry, and object-service integrations.
apps/api/src/box/runner-adapter/runnerAdapter.ts - Fleet runner · Polls and executes scheduled workload operations.
apps/runner/cmd/runner/main.go - Runner BoxLite adapter · Invokes BoxLite on runner hosts.
apps/runner/pkg/boxlite/client.go - Dashboard
apps/dashboard/src/main.tsx - Generated API client
apps/libs/api-client/src/index.ts - Cloud deployment · Deploys platform services and observability components.
apps/infra/sst.config.ts
Connections 23
- CLI → Runtime core: local commands
- Standalone REST server → Runtime core: runtime actions
- Language SDKs → Runtime core: native bindings
- Runtime core → Box lifecycle: lifecycle
- Box lifecycle → OCI image pipeline: prepare rootfs
- Box lifecycle → Persistent storage: preserve state
- Box lifecycle → Host isolation: sandbox VM
- Box lifecycle → VMM abstraction: launch VM
- VMM abstraction → libkrun backend: platform backend
- Box lifecycle → Network forwarding: configure forwarding
- VMM abstraction → Guest service: hosts guest
- Runtime core → Shared control protocol: control channel
- Shared control protocol → Guest service: serves
- Guest service → Guest containers: lifecycle and exec
- Dashboard → Generated API client: uses
- Generated API client → Control-plane API: control requests
- Control-plane API → Identity and tenancy: authorize and scope
- Control-plane API → Cloud data services: state, jobs, events
- Control-plane API → Fleet runner: desired state and jobs · Control-plane-to-compute scheduling boundary.
- Fleet runner → Runner BoxLite adapter: execute locally
- Runner BoxLite adapter → Runtime core: host workloads
- Cloud deployment → Control-plane API: deploys
- Cloud deployment → Fleet runner: deploys