SDK API References
Complete API documentation for each SDK:| SDK | Description |
|---|---|
| Python | Async/sync API, box types, metrics |
| Node.js | TypeScript definitions, box types, CDP endpoints |
| Rust | Core runtime, stream APIs, security options |
| C | FFI bindings, JSON API, callback streaming |
Python SDK
Async and sync APIs, box types, code execution, metrics. Python 3.10+.
Node.js SDK
TypeScript definitions, box types, CDP endpoints for browser automation.
Rust SDK
Core runtime, stream APIs, security options. Native performance.
C SDK
FFI bindings, JSON API, callback streaming for system-level integration.
Quick Reference
Python API
For complete Python API documentation, see Python API Reference. Key Classes:| Class | Description |
|---|---|
Boxlite | Main runtime for creating and managing boxes |
Box | Handle to a running or stopped box |
SimpleBox | Context manager for basic execution |
CodeBox | Specialized box for Python code execution |
BrowserBox | Box configured for browser automation |
ComputerBox | Box with desktop automation capabilities |
InteractiveBox | Box for interactive shell sessions |
Node.js API
For complete Node.js API documentation, see Node.js API Reference. Key Classes:| Class | Description |
|---|---|
SimpleBox | Basic container for command execution |
CodeBox | Python code execution sandbox |
BrowserBox | Browser automation with CDP endpoint |
ComputerBox | Desktop automation (14 methods) |
InteractiveBox | PTY terminal sessions |
Rust API
For complete Rust API documentation, see Rust API Reference. Core Types:C API
For complete C API documentation, see C API Reference. Functions:| Function | Description |
|---|---|
boxlite_runtime_new | Create runtime instance |
boxlite_create_box | Create a new box |
boxlite_execute | Run command with streaming |
boxlite_stop_box | Stop and free box |
SDK Feature Comparison
| Feature | Python | Node.js | Rust | C |
|---|---|---|---|---|
| Async API | Yes | Yes | Yes | Callback-based |
| Sync API | Yes (greenlet) | No | Yes (blocking) | Yes |
| SimpleBox | Yes | Yes | Yes | Yes |
| CodeBox | Yes | Yes | No | No |
| BrowserBox | Yes | Yes | No | No |
| ComputerBox | Yes | Yes | No | No |
| InteractiveBox | Yes | Yes | No | No |
| Streaming I/O | Yes | Yes | Yes | Yes |
| Metrics | Yes | Yes | Yes | Yes |
| Type Safety | Type hints | TypeScript | Native | Manual |
Configuration Reference
BoxOptions Parameters
Complete reference for box configuration options.image: String
OCI image URI to use for the box rootfs.
Format: [registry/]repository[:tag]
Default: "python:slim" (for Python SDK convenience wrappers)
Examples:
Images are pulled on first use and cached in
~/.boxlite/images/. Layer-level caching ensures fast subsequent starts. For private registries, use registry-specific authentication (Docker credentials, etc.).cpus: int
Number of CPU cores allocated to the box.
Default: 1
Range: 1 to host CPU count
Example:
CPU scheduling is proportional (shares-based). It does not reserve physical cores, just scheduling weight. Monitor actual usage with
box.metrics().cpu_time_ms.memory_mib: int
Memory limit in mebibytes (MiB).
Default: 512
Range: 128 to 65536 (64 GiB)
Example:
1 MiB = 1024 KiB = 1,048,576 bytes. Minimum 128 MiB is required for most images. Out of memory kills the box process. Monitor with
box.metrics().memory_usage_bytes.disk_size_gb: int | None
Create a persistent QCOW2 disk image.
Default: None (ephemeral storage only)
Range: 1 to 1024 (1 TB)
Example:
Disk persists across stop/restart. Stored at
~/.boxlite/boxes/{box-id}/disk.qcow2. Uses copy-on-write (thin provisioned). Deleted when box is removed.working_dir: str
Working directory for command execution inside the box.
Default: "/root"
Example:
Directory must exist in the container image. Commands execute with this as
$PWD.env: List[Tuple[str, str]]
Environment variables as (key, value) pairs.
Default: [] (inherit from image)
Example:
Variables are appended to the image environment. Use to override image defaults (e.g.,
PATH). Sensitive values (API keys, passwords) are visible in box metadata.volumes: List[Tuple[str, str, str]]
Volume mounts as (host_path, guest_path, mode) tuples.
Format: (host_path, guest_path, "ro"|"rw")
Default: [] (no mounts)
Example:
Uses virtiofs for high-performance file sharing. Host path must exist before box creation. Guest path is created automatically if missing. Changes to
rw mounts are visible on host immediately.ports: List[Tuple[int, int, str]]
Port forwarding as (host_port, guest_port, protocol) tuples.
Format: (host_port, guest_port, "tcp"|"udp")
Default: [] (no port forwarding)
Example:
Uses gvproxy for NAT port mapping. Host port must be available (not in use). Multiple boxes can forward to same host port (error if conflict). Supports both TCP and UDP protocols.
auto_remove: bool
Automatically remove box when stopped.
Default: True
Example:
When
True, box is removed when context exits or stop() is called. When False, box persists after stop and can be restarted with runtime.get(box_id). Manual cleanup is done with await box.remove().Runtime Options
home_dir: str
Base directory for BoxLite runtime data.
Default: ~/.boxlite
Override: Set BOXLITE_HOME environment variable
Structure:
Environment Variables
BOXLITE_HOME
Override default runtime home directory.
Default: ~/.boxlite
Example:
RUST_LOG
Enable debug logging for troubleshooting.
Levels: trace, debug, info, warn, error
Example:
BOXLITE_TMPDIR
Override temporary directory for BoxLite operations.
Default: System temp directory (/tmp on Linux/macOS)
Example:
Error Codes & Handling
For a detailed breakdown of error types and handling patterns, see the error documentation for each SDK:Error Types
BoxLite uses a centralized error enum with specific variants for different error categories.| Error | Description |
|---|---|
UnsupportedEngine | Platform or hypervisor not supported |
Engine(String) | Hypervisor or VM engine error |
Config(String) | Invalid box configuration |
Storage(String) | Filesystem or disk operation error |
Image(String) | OCI image pull or extraction error |
Portal(String) | Host-guest communication error (gRPC over vsock) |
Network(String) | Network configuration or connectivity error |
Execution(String) | Command execution error |
Internal(String) | Internal BoxLite error |
NotFound(String) | Box or resource not found |
AlreadyExists(String) | Box or resource already exists |
InvalidState(String) | Box is in wrong state for requested operation |
Error Handling Pattern (Python)
Error Handling Pattern (Rust)
File Formats
QCOW2 Disk Images
BoxLite uses QCOW2 (QEMU Copy-On-Write version 2) for persistent disks. Location:~/.boxlite/boxes/{box-id}/disk.qcow2
Features:
- Thin provisioning (sparse allocation)
- Copy-on-write snapshots
- Compression support
OCI Image Cache
BoxLite caches OCI images at the layer level for fast starts. Location:~/.boxlite/images/
Structure:
Blob-level deduplication across images means shared base layers (e.g.,
python:3.11 and python:3.12) are stored only once.Box Configuration
Box metadata and state are stored as JSON. Location:~/.boxlite/boxes/{box-id}/config.json
Example:
SQLite Databases
BoxLite uses SQLite for metadata persistence. Locations:~/.boxlite/db/boxes.db- Box registry and metadata~/.boxlite/db/images.db- Image cache index