use statements, #[tokio::main], and error handling are already filled in. The crate itself is the source of truth (src/boxlite/src/); check the version you have with boxlite::VERSION, which equals CARGO_PKG_VERSION.
Prerequisites
- The
boxlitecrate and a machine with hardware virtualization — see Installation.
Cargo.toml (the crate name is boxlite):
Note: BoxLite is currently distributed primarily alongside the per-language SDKs and the CLI. If your environment has no publish source configured yet, depend on this repository’ssrc/boxlite/by path (boxlite = { path = "..." }). The crate version is managed centrally by the workspace and corresponds to the latest published release (boxlite::VERSIONreadsCARGO_PKG_VERSIONat compile time).
Quick Example (minimal happy path)
The shortest “create a box -> run a command -> read the exit code -> clean up” loop. The execution method isexec (not run); once it completes you obtain an ExecResult via Execution::wait():
Key points
- The runtime constructors (
with_defaults/new/rest) are synchronousfn; only the operations (create/exec/start/stop, etc.) areasync.- The execution method is
execand returns anExecution. There is nolitebox.run(...).ExecResulthas onlyexit_codeanderror_message, not stdout/stderr — output is read as a stream (see Execution).- To delete a box use
runtime.remove(id_or_name, force), notbox.remove().
Core types and methods
BoxliteRuntime (runtime entry point)
The main entry point for creating and managing boxes. Source: src/boxlite/src/runtime/core.rs.
Constructors (all synchronous fn)
Operations (all
async, &self)
Non-async handles:
images() -> BoxliteResult<ImageHandle>, auth() -> BoxliteResult<AuthHandle>.
Note:metrics()returnsBoxliteResult<RuntimeMetrics>(needs?). To enumerate boxes uselist_info()(notlist()).
LiteBox (box handle)
A handle to a box instance. All methods take &self, so it can be shared across threads via Arc. Source: src/boxlite/src/litebox/mod.rs.
Lifecycle:
create() -> Configured (persisted, no VM); start() (or the first exec()) -> Running; stop() -> Stopped (can be restarted).
BoxCommand (command builder)
Builder style, chained methods that consume self. Source: src/boxlite/src/litebox/exec.rs.
Execution (handle to a running command)
Returned by exec(). Source: src/boxlite/src/litebox/exec.rs. stdout/stderr implement futures::Stream<Item = String> and can each be taken only once.
Note:Streaming read of stdout (complete, runnable):wait/kill/signal/resize_ttyall take&self(onlystdin/stdout/stderr, which take a stream, take&mut self). This means you can share anArc<Execution>and callkill()concurrently.
ExecStdin provides write / write_all / close):
ExecResult
No stdout/stderr fields (this differs from the C / Go / Python wrapper layers, which add output fields). At the Rust core layer, output comes from the streams in Execution.
Box configuration (BoxOptions and related types)
Source: src/boxlite/src/runtime/options.rs. BoxOptions implements Default; fill the remaining fields with ..Default::default().
BoxOptions fields
About thecpus/memory_mibdefaults: the field default isNone. WhenNone, the runtime allocates 1 vCPU / 1024 MiB fromvm_defaultsinsrc/boxlite/src/runtime/constants.rs. Pass explicit values in production. See Compute resources.
RootfsSpec
VolumeSpec (third field is a bool)
Note: thero/rwstrings are only used by the CLI form-v host:guest:ro, which lives in the CLI parsing layer; the SDK API uses a bool.
NetworkSpec
PortSpec
Secret (secrets / vault entry point)
Code inside the box sees the placeholder; when traffic goes out to one of the hosts listed in hosts, the proxy substitutes the real value, so the plaintext never lands in the guest:
Security, metrics, and runtime options
SecurityOptions / AdvancedBoxOptions
Security options are passed through advanced; the top-level BoxOptions has no security field. Source: src/boxlite/src/runtime/advanced_options.rs.
The Rust core layer exposes a two-state switch plus a builder (unlike the Python binding’s development()/standard()/maximum() preset static methods, which do not exist here):
SecurityOptions fields
The struct fields and their meanings (source: SecurityOptions in src/boxlite/src/runtime/advanced_options.rs). Several fields are Linux-only or macOS-only; on a platform that does not support a feature the field is inert.
enabled() (== default(), source: SecurityOptions::enabled in advanced_options.rs):
disabled() sets jailer_enabled = false and turns off every sub-protection (uid/gid become None).
SecurityOptionsBuilder methods
Obtain a builder with SecurityOptions::builder() (or SecurityOptionsBuilder::enabled() / ::disabled() / ::new()). The setters take &mut self (non-consuming), and build() produces the final SecurityOptions (source SecurityOptionsBuilder in advanced_options.rs):
Note: thedevelopment()/standard()/maximum()presets available in the Python binding are not present on the RustSecurityOptionsBuilder. Useenabled()/disabled()/new()as starting points and override individual fields.
ResourceLimits
RLIMIT_* caps applied to the jailed process (source: ResourceLimits in advanced_options.rs). Each field maps to a POSIX resource limit; None means “do not set this limit”.
&mut self (non-consuming) and ends with build(). The following is a complete, runnable example: build custom security options with the builder and attach them to AdvancedBoxOptions.security:
AdvancedBoxOptions fields: security: SecurityOptions, isolate_mounts: bool (default false, requires CAP_SYS_ADMIN on Linux), health_check: Option<HealthCheckOptions>.
Metrics fields (real field and method names)
Accessor methods onRuntimeMetrics (runtime.metrics().await?):
Public fields on
BoxMetrics (litebox.metrics().await?, selected):
BoxliteOptions / ImageRegistry (runtime options)
Customize the home directory and image registries (including resolution order, authentication, plain HTTP, and skipping TLS verification):
ImageRegistry constructors: https(host) / http(host), chained with .with_search(bool) / .with_skip_verify(bool) / .with_basic_auth(user, pass) / .with_bearer_auth(token).
State queries (BoxInfo / BoxStatus / BoxState)
litebox.info().await? returns a BoxInfo. At the Rust core layer, BoxInfo has a status: BoxStatus field directly (this differs from the Python/Node binding layer, where it is the two-level info.state.status).
BoxInfo fields: id: BoxID, name: Option<String>, status: BoxStatus, created_at, last_updated, pid: Option<u32>, image: String, cpus: u8, memory_mib: u32, labels, health_status: HealthStatus.
is_running() / is_configured() / is_stopped() / is_active() / is_transient() / can_start() / can_stop() / can_remove() / can_exec().
BoxState
The dynamic state of a box (changes over the lifecycle), as opposed to the static configuration. Source src/boxlite/src/litebox/state.rs (struct BoxState):
When a box reportsFailed,error_reasonandexit_codeare where the cause is. Both areNonewhile the box is healthy.
Type utilities (Bytes / Seconds / BoxID / ContainerID)
These newtypes appear across the API (resource sizes, durations, identifiers). Source src/boxlite/src/runtime/types.rs and src/boxlite/src/runtime/id.rs.
Bytes
A semantic newtype for byte sizes, so call sites carry units instead of bare integers.
Seconds
A semantic newtype for durations.
BoxID
A box identifier. Locally minted IDs are 12-character Base62 (~71 bits of entropy); the type also accepts other formats from remote REST servers (up to MAX_LENGTH = 128 characters) so prefixed or namespaced IDs round-trip.
ContainerID
A container identifier in OCI format: 64-character lowercase hex.
Error types (BoxliteError)
Source src/shared/src/errors.rs. BoxliteResult<T> = Result<T, BoxliteError>.
Real variants (there is no BoxliteError::Run — command-execution errors are Execution):
UnsupportedEngine, Engine(String), Config(String), Storage(String), Image(String), Portal(String), Network(String), Rpc(String), RpcTransport(String), Internal(String), Execution(String), Unsupported(String), NotFound(String), AlreadyExists(String), InvalidState(String), Database(String), MetadataError(String), InvalidArgument(String), Stopped(String), ResourceExhausted(String), SessionReaped(String).
Concurrency and thread safety
BoxliteRuntime and LiteBox are both Send + Sync and can be shared across tasks via Arc:
Troubleshooting (common problems and typical errors)
Related references
- Resource defaults (
cpus/memory_mib): the field default isNone, and the runtime then allocates 1 vCPU / 1024 MiB; pass explicit values in production. See Compute resources. - Binding-layer differences: the Python/Node two-level
BoxInfo.state.status, the PythonSecurityOptions.maximum()preset, and so on — see the corresponding SDK reference pages.

