Overview
The C SDK provides C-compatible FFI bindings for integrating BoxLite into C/C++ applications. Library:libboxlite
Header: boxlite.h
Version: 0.2.0
API Styles
The SDK provides two API styles:-
Simple API (
boxlite_simple_*) - Convenience layer for common use cases- No JSON required
- Auto-managed runtime
- Buffered command results
-
Native API (
boxlite_*) - Full-featured, flexible interface- JSON configuration
- Streaming output callbacks
- Advanced features (volumes, networking, etc.)
Quick Start
Simple API (Recommended)
Native API (Full Control)
Building
Runtime Functions
boxlite_version
Get BoxLite version string."0.5.7".
boxlite_runtime_new
Create a new runtime instance.Parameters
| Parameter | Type | Description |
|---|---|---|
home_dir | const char* | Path to BoxLite home. NULL = default (~/.boxlite) |
registries_json | const char* | JSON array of registries. NULL = ["docker.io"] |
out_runtime | CBoxliteRuntime** | Output: runtime handle |
out_error | CBoxliteError* | Output: error information |
Example
boxlite_runtime_shutdown
Gracefully stop all running boxes.Parameters
| Parameter | Type | Description |
|---|---|---|
runtime | CBoxliteRuntime* | Runtime instance |
timeout | int | Seconds: 0=default(10), -1=infinite, >0=custom |
out_error | CBoxliteError* | Output: error information |
boxlite_runtime_free
Free a runtime instance.Simple API
The Simple API provides a streamlined interface for common use cases without JSON configuration.boxlite_simple_new
Create and auto-start a box with sensible defaults.Parameters
| Parameter | Type | Description |
|---|---|---|
image | const char* | OCI image reference (e.g., "python:slim", "alpine:3.19") |
cpus | int | Number of CPUs (0 = default: 2) |
memory_mib | int | Memory in MiB (0 = default: 512) |
out_box | CBoxliteSimple** | Output: created box handle |
out_error | CBoxliteError* | Output: error information |
Returns
BoxliteErrorCode - Ok on success, error code on failure.
Example
boxlite_simple_run
Run a command and get buffered result.Parameters
| Parameter | Type | Description |
|---|---|---|
box | CBoxliteSimple* | Box handle from boxlite_simple_new |
command | const char* | Command to execute |
args | const char* const* | NULL-terminated array of arguments |
argc | int | Number of arguments (excluding NULL terminator) |
out_result | CBoxliteExecResult** | Output: execution result |
out_error | CBoxliteError* | Output: error information |
Result Structure
Example
boxlite_simple_free
Free a simple box (auto-stops and removes).boxlite_result_free
Free an execution result.Platform Requirements
| Platform | Architecture | Status | Requirements |
|---|---|---|---|
| macOS | ARM64 (Apple Silicon) | Supported | macOS 11.0+, Hypervisor.framework |
| macOS | x86_64 (Intel) | Not supported | N/A |
| Linux | x86_64 | Supported | KVM enabled |
| Linux | ARM64 (aarch64) | Supported | KVM enabled |
| Windows | Any | Via WSL2 | WSL2 with KVM |
API Summary
| Function | Description |
|---|---|
boxlite_version() | Get version string |
boxlite_runtime_new() | Create runtime |
boxlite_runtime_shutdown() | Graceful shutdown |
boxlite_runtime_free() | Free runtime |
boxlite_runtime_metrics() | Get runtime metrics |
boxlite_create_box() | Create box |
boxlite_start_box() | Start/restart box |
boxlite_stop_box() | Stop box |
boxlite_remove() | Remove box |
boxlite_get() | Reattach to box |
boxlite_box_id() | Get box ID |
boxlite_box_info() | Get box info |
boxlite_box_metrics() | Get box metrics |
boxlite_execute() | Execute command |
boxlite_list_info() | List all boxes |
boxlite_get_info() | Get box info by ID |
boxlite_simple_new() | Create simple box |
boxlite_simple_run() | Run command (simple) |
boxlite_simple_free() | Free simple box |
boxlite_result_free() | Free exec result |
boxlite_free_string() | Free string |
boxlite_error_free() | Free error |
See Also
Native API
Box creation, command execution, and lifecycle functions for full control over BoxLite.
Memory, JSON & Threading
Memory management rules, JSON schema reference, and thread safety patterns.
Errors & Metrics
Error codes, error handling patterns, and runtime/box metrics.
C Quick Start
Get up and running with the C SDK in 5 minutes.