Skip to main content
Complete API reference for the BoxLite Node.js/TypeScript SDK. Version: 0.1.6 Node.js: 18+ Platforms: macOS (Apple Silicon), Linux (x86_64, ARM64)

Overview

The BoxLite Node.js SDK provides a TypeScript-first API for creating and managing lightweight virtual machine sandboxes. It supports multiple box types for different use cases — from simple command execution to full desktop automation.
import { JsBoxlite, SimpleBox, CodeBox, BrowserBox, ComputerBox } from 'boxlite';

Installation

Install the SDK via npm:
npm install boxlite
Or with yarn:
yarn add boxlite
BoxLite requires Node.js 18 or later. The native binary is bundled for macOS (Apple Silicon) and Linux (x86_64, ARM64).

Runtime Management

JsBoxlite / Boxlite

The main runtime for creating and managing boxes.
import { JsBoxlite } from 'boxlite';
// or use the wrapper classes
import { SimpleBox } from 'boxlite';

Constructor

new JsBoxlite(options: JsOptions)

Static Methods

MethodSignatureDescription
withDefaultConfig()() => JsBoxliteGet runtime with default config (~/.boxlite)
initDefault()(options: JsOptions) => voidInitialize default runtime with custom options

Instance Methods

MethodSignatureDescription
create()(options: JsBoxOptions, name?: string) => Promise<JsBox>Create a new box
listInfo()() => Promise<JsBoxInfo[]>List all boxes
getInfo()(idOrName: string) => Promise<JsBoxInfo | null>Get box info
get()(idOrName: string) => Promise<JsBox | null>Get box handle
metrics()() => Promise<JsRuntimeMetrics>Get runtime metrics
remove()(idOrName: string, force?: boolean) => Promise<void>Remove a box
close()() => voidClose runtime (no-op)

Example

// Default runtime
const runtime = JsBoxlite.withDefaultConfig();

// Custom runtime
const runtime = new JsBoxlite({ homeDir: '/custom/path' });

// Create a box
const box = await runtime.create({
  image: 'alpine:latest',
  cpus: 2,
  memoryMib: 512
}, 'my-box');

// List all boxes
const boxes = await runtime.listInfo();
boxes.forEach(info => console.log(`${info.id}: ${info.status}`));

Options

JsOptions

Runtime configuration options.
FieldTypeDefaultDescription
homeDirstring~/.boxliteBase directory for runtime data
imageRegistriesstring[][]Custom image registries for unqualified references

JsBoxOptions

Configuration options for creating a box.
FieldTypeDefaultDescription
imagestring-OCI image URI
rootfsPathstring-Pre-prepared rootfs directory (alternative to image)
cpusnumber1Number of CPU cores
memoryMibnumber512Memory limit in MiB
diskSizeGbnumber-Persistent disk size in GB
workingDirstring"/root"Working directory inside container
envJsEnvVar[][]Environment variables
volumesJsVolumeSpec[][]Volume mounts
networkstring"isolated"Network mode
portsJsPortSpec[][]Port mappings
autoRemovebooleanfalseAuto cleanup when stopped
detachbooleanfalseSurvive parent process exit

JsEnvVar

interface JsEnvVar {
  key: string;
  value: string;
}

JsVolumeSpec

interface JsVolumeSpec {
  hostPath: string;    // Path on host
  guestPath: string;   // Path in container
  readOnly?: boolean;  // Default: false
}

JsPortSpec

interface JsPortSpec {
  hostPort?: number;   // None = auto-assign
  guestPort: number;   // Port inside container
  protocol?: string;   // "tcp" or "udp" (default: "tcp")
  hostIp?: string;     // Default: "0.0.0.0"
}

Constants

Default values used by BoxLite.

Resource Defaults

ConstantValueDescription
DEFAULT_CPUS1Default CPU cores
DEFAULT_MEMORY_MIB512Default memory in MiB

ComputerBox Defaults

ConstantValueDescription
COMPUTERBOX_CPUS2Default CPUs
COMPUTERBOX_MEMORY_MIB2048Default memory
COMPUTERBOX_DISPLAY_WIDTH1024Screen width
COMPUTERBOX_DISPLAY_HEIGHT768Screen height
COMPUTERBOX_GUI_HTTP_PORT3000HTTP GUI port
COMPUTERBOX_GUI_HTTPS_PORT3001HTTPS GUI port
DESKTOP_READY_TIMEOUT60Ready timeout (seconds)

BrowserBox Ports

ConstantValueDescription
BROWSERBOX_PORT_CHROMIUM9222Chromium CDP port
BROWSERBOX_PORT_FIREFOX9223Firefox CDP port
BROWSERBOX_PORT_WEBKIT9224WebKit CDP port

See Also