boxlite to run a command in an isolated microVM sandbox within minutes, getting streaming output and an exit code without managing virtual machines, images, or networking yourself. This is the shortest path to safely executing untrusted code, AI-generated code, or third-party commands.
Prerequisites
- The
boxlitecrate and a machine with hardware virtualization — see Installation for the supported platforms. - Rust 1.88 or newer (
rustc --versionto check).
Quick Example
Write the following intosrc/main.rs, then run cargo run. This code is standalone and includes the full imports, runtime initialization, and error propagation (? + Box<dyn Error>).
Parameters and Returns (Core API)
BoxliteRuntime (runtime handle)
The constructors are synchronous fns (do not .await); only create / exec / remove and similar operations are async.
LiteBox (box handle)
BoxCommand (command builder)
Chained construction; all methods return Self:
Execution / ExecResult (execution handle and result)
Important: the Rust core-layerExecResultcontains onlyexit_code(anderror_message), not stdout/stderr; output must be read via the streamingstdout()/stderr()above. This differs from the C/Go/Python SDKs.
BoxOptions (common fields)
Mount a host directory (
read_only is a bool, not a string):
Troubleshooting
Method run not found / BoxliteError::Run
exec, not run. Likewise, the error enum has no BoxliteError::Run variant; the variant for a command execution failure is BoxliteError::Execution(String). When matching errors:
A non-zero exit code was not reported as an error
Even when the command fails,execution.wait() still returns Ok(ExecResult): a non-zero exit code is not turned into an Err. Check it yourself:
Compile error: missing StreamExt / .next() not found
futures::StreamExt trait, and the futures dependency must be present:
Mixing async and synchronous methods
BoxliteRuntime::default_runtime() / with_defaults() / new(), and litebox.id() / litebox.info(), are synchronous; do not .await them. Only create / start / exec / wait / stop / metrics are async.
Startup failure: no hardware virtualization (environment constraint)
On Linux without KVM (or a container/CI that does not pass through/dev/kvm), create / start fail:
- Linux: confirm
/dev/kvmexists and the current user is in thekvmgroup (ls -l /dev/kvm). - macOS (Apple Silicon): uses Hypervisor.framework and does not need
/dev/kvm; runs directly. - WSL2: enable nested virtualization and install KVM.
Err with the match above to handle it cleanly.
The first run stalls while pulling the image
The first use of an image (such asalpine:latest) downloads it from a registry, which can be slow depending on the network; a failure usually surfaces as BoxliteError::Image(...) or BoxliteError::Network(...), which is retryable.
Next Steps
- Run any language’s code inside a box, mount volumes, or configure networking: replace
BoxCommandwith your target command andRootfsSpec::Image(...)with the image you need (such aspython:3.11-slim). - For stronger isolation, configure the security options under
BoxOptions.advanced. - Other languages: see the Python quickstart, the Node.js quickstart, and the Go quickstart.

