Prerequisites
- The
@boxlite-ai/boxliteNode package and a machine with hardware virtualization — see Installation.
If the platform does not meet the virtualization requirement, the Box fails to start but the process does not crash; see Troubleshooting below.
Installation
package.json is an ESM project (the SDK is published as ESM only):
Quick Example
Createhello.mjs (or a .js file in a "type": "module" project); it is runnable as-is:
- On the first run, BoxLite pulls the
alpine:latestOCI image (later runs hit the local cache). - The Box is lazily created and starts a microVM on the first
exec(). - The command runs inside the VM, collecting stdout/stderr/exit code.
stop()stops the VM and cleans up (autoRemovedefaults totrue).
TypeScript 5.2+: await using for automatic cleanup
SimpleBox implements Symbol.asyncDispose, so it calls stop() automatically when leaving scope — no try/finally needed:
Common execution variants
Parameters and Returns
new SimpleBox(options) common fields
SimpleBoxOptions (the full field list is in the SDK type definitions; the table below covers the most common):
box.exec(...) overloads
The timeout parameter in the wrapper-layerSimpleBox.execis calledtimeoutSecs(inside theoptionsobject).
ExecResult (the return value of exec)
box.info() return value (JsBoxInfo, a synchronous method)
The correct path to the state string isbox.info().state.status(the outer field isstate, the inner field isstatus).info()is synchronous; do notawaitit. The async version isgetInfo().
Troubleshooting
Cannot find package 'boxlite' / module not found
The package name has a scope. Both install and import must use @boxlite-ai/boxlite:
Cannot use import statement outside a module / require is not defined
The SDK is published as ESM only. Add "type": "module" to package.json, or rename the file to .mjs, and use import rather than require.
A command failed but no exception was raised
exec does not raise on a non-zero exit code; it only places the code into ExecResult.exitCode. Always check it explicitly:
A missing command / startup failure raises a bare Error
When a command is not found inside the Box, or the underlying start fails, the error raised may be a standard Error (instanceof BoxliteError === false), with a message like internal error: spawn_failed: .... Do not assume the exception is always an ExecError/BoxliteError:
Image pull failure (network problem)
The first run needs network access to pull the image. On a network error or an unreachable registry, an error is raised. Catch and retry, or pull ahead of time:No hardware virtualization → the Box cannot start
- Linux: confirm
/dev/kvmexists and the current user is in thekvmgroup (ls -l /dev/kvm). - macOS Intel: not supported.
- WSL2: enable KVM inside WSL.
- macOS ARM64: uses Hypervisor.framework by default, no extra configuration needed.
The volume readOnly was passed as a string
In the SDK layer, the volume read-only marker is a boolean, not the CLI’s "ro"/"rw" string:
Next Steps
- Run the bundled SDK examples in the repository:
examples/node/simplebox.js(basic execution),codebox.js(code execution sandbox),browserbox.js,computerbox.js, andinteractivebox.js. - To run a Python/JS snippet and get its output directly, see
CodeBox(fixed language image,run(code)in one step). - Other languages: see the Python quickstart, the Rust quickstart, and the Go quickstart.

