Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

5.3 KB
Raw Blame

Security

Defense-in-depth security layer that sandboxes the shim process, inspired by Firecracker's jailer. Provides OS-level isolation on top of hardware virtualization.

Key responsibilities:

  • OS-level process isolation for shim
  • Syscall filtering and sandboxing
  • Resource limit enforcement
  • Environment sanitization

Security layers:

Linux:

  • Namespace isolation (mount, PID, network)
  • Chroot/pivot_root for filesystem isolation
  • Seccomp BPF for syscall filtering
  • Privilege dropping (unprivileged user)
  • cgroups v2 for resource limits

macOS:

  • sandbox-exec (Seatbelt) for kernel-enforced sandboxing
  • rlimits for resource constraints

Architecture:

┌─────────────────────────────────────────────────────────────────────┐
│                              HOST OS                                │
│  ┌───────────────────────────────────────────────────────────────┐  │
│  │                      JAILER BOUNDARY                          │  │
│  │  ┌─────────────────────────────────────────────────────────┐  │  │
│  │  │                  SHIM PROCESS (sandboxed)               │  │  │
│  │  │  ┌───────────────────────────────────────────────────┐  │  │  │
│  │  │  │              VM (libkrun/KVM)                     │  │  │  │
│  │  │  │  ┌─────────────────────────────────────────────┐  │  │  │  │
│  │  │  │  │            GUEST (untrusted)                │  │  │  │  │
│  │  │  │  └─────────────────────────────────────────────┘  │  │  │  │
│  │  │  └───────────────────────────────────────────────────┘  │  │  │
│  │  └─────────────────────────────────────────────────────────┘  │  │
│  └───────────────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────────────┘

Configuration:

use boxlite::{AdvancedBoxOptions, BoxOptions, SecurityOptions};

// Most users don't need to configure security — defaults prioritize compatibility
// For advanced users who need maximum isolation:
let opts = BoxOptions {
    advanced: AdvancedBoxOptions {
        security: SecurityOptions::enabled(),
        ..Default::default()
    },
    ..Default::default()
};

See the jailer threat model for isolation boundaries, and jailer network permissions for guest networking and host access.

Shim binary cache

Jailed boxes in the same runtime home share a content-addressed cache of the shim binary and its firmware. On a cache miss, singleflight staging lets concurrent requests for the same shim source and cache reuse one build. Per-source file locks and stable digest memos live in <runtime home>/shims.sources, next to <runtime home>/shims, so lock state never appears among the 16-digit hex generation directories. The builder copies the files into a unique staging directory, writes the .complete marker, and atomically renames the directory into place so readers never see a partially staged generation.

In-process RwLocks let cache hits read the digest memo and validate staged entries concurrently. Memo updates, publication, and marker refreshes use exclusive access to their respective state. During cleanup_stale, the in-process LIFECYCLE_LOCK write lock is acquired only in retire_if_stale to re-check expiration and atomically rename a stale directory out of the cache namespace; directory scanning, initial metadata checks, and deleting moved-out directories or expired .staging.* orphan directories run outside the lock, and the lock applies only within a single process. Staging also bounds how long it waits on the in-process singleflight and per-source file locks, falling back to the original shim if the timeout expires.

On a cache hit, the .complete marker (STAMP) is refreshed only when its modification time is at least 60 seconds old. The cache uses metadata already read during validation, avoiding a separate stat for the refresh decision and skipping most mtime update syscalls. Cache hits still validate the staged files.