Static methods
Sandbox.create()
| Name | Type | Description |
|---|---|---|
| config | SandboxConfig | Sandbox configuration |
| Type | Description |
|---|---|
Sandbox | Running sandbox |
Sandbox.createDetached()
Sandbox.get().
Parameters
| Name | Type | Description |
|---|---|---|
| config | SandboxConfig | Sandbox configuration |
| Type | Description |
|---|---|
Sandbox | Running sandbox |
Sandbox.get()
| Name | Type | Description |
|---|---|---|
| name | string | Sandbox name |
| Type | Description |
|---|---|
SandboxHandle | Handle with status and lifecycle control |
Sandbox.list()
| Type | Description |
|---|---|
Array<SandboxInfo> | All sandboxes |
Sandbox.remove()
| Name | Type | Description |
|---|---|---|
| name | string | Sandbox name |
Sandbox.start()
| Name | Type | Description |
|---|---|---|
| name | string | Name of a stopped sandbox |
| Type | Description |
|---|---|
Sandbox | Running sandbox |
Sandbox.startDetached()
| Name | Type | Description |
|---|---|---|
| name | string | Name of a stopped sandbox |
| Type | Description |
|---|---|
Sandbox | Running sandbox |
Instance properties
name
ownsLifecycle
true in attached mode, false in detached mode.
Instance methods
detach()
Sandbox.get().
drain()
exec calls are rejected.
fs()
| Type | Description |
|---|---|
SandboxFs | Filesystem handle |
kill()
metrics()
| Type | Description |
|---|---|
SandboxMetrics | CPU, memory, disk, network metrics |
metricsStream()
recv() and for await...of.
Parameters
| Name | Type | Description |
|---|---|---|
| intervalMs | number | Milliseconds between metric snapshots |
| Type | Description |
|---|---|
MetricsStream | Async stream of metrics |
removePersisted()
stop()
stopAndWait()
| Type | Description |
|---|---|
ExitStatus | Exit code and success flag |
wait()
| Type | Description |
|---|---|
ExitStatus | Exit code and success flag |
Types
LogLevel
Sandbox process log verbosity.| Value | Description |
|---|---|
'debug' | Debug and higher |
'error' | Errors only |
'info' | Info and higher |
'trace' | Most verbose - all diagnostic output |
'warn' | Warnings and errors only |
MetricsStream
Async stream for receiving periodic metrics snapshots.| Method | Returns | Description |
|---|---|---|
| [Symbol.asyncIterator] | AsyncGenerator<SandboxMetrics> | Use with for await...of |
| recv() | Promise<SandboxMetrics | null> | Receive next snapshot. Returns null when the stream ends. |
PullPolicy
Controls when the SDK fetches an OCI image from the registry.| Value | Description |
|---|---|
'always' | Pull the image every time, even if cached locally |
'if-missing' | Pull only if the image is not already cached. This is the default. |
'never' | Never pull; fail if the image is not cached locally |
SandboxConfig
Configuration object passed toSandbox.create() and Sandbox.createDetached().
| Field | Type | Default | Description |
|---|---|---|---|
| cpus? | number | 1 | Virtual CPUs |
| entrypoint? | Array<string> | - | Override image entrypoint |
| env? | Record<string, string> | {} | Environment variables visible to all commands |
| hostname? | string | - | Guest hostname |
| image | string | - | OCI image, local path, or disk image (required) |
| logLevel? | LogLevel | - | Override log verbosity |
| maxDurationSecs? | number | - | Maximum sandbox lifetime in seconds |
| memoryMib? | number | 512 | Guest memory in MiB. This is a limit, not a reservation. |
| name | string | - | Sandbox name (required) |
| network? | NetworkConfig | publicOnly | Network policy and configuration |
| patches? | Array<PatchConfig> | [] | Rootfs modifications applied before boot |
| ports? | Record<string, number> | {} | Port mappings ("hostPort": guestPort) |
| pullPolicy? | PullPolicy | 'if-missing' | Image pull behavior |
| quietLogs? | boolean | false | Suppress log output |
| registryAuth? | { username: string, password: string } | - | Private registry credentials |
| replace? | boolean | false | Replace existing sandbox with same name |
| scripts? | Record<string, string> | {} | Named scripts mounted at /.msb/scripts/ |
| secrets? | Array<SecretEntry> | [] | Secret injection |
| shell? | string | /bin/sh | Shell for shell() calls |
| user? | string | - | Default guest user |
| volumes? | Record<string, MountConfig> | {} | Volume mounts. See Volumes. |
| workdir? | string | - | Default working directory for commands |
SandboxHandle
A lightweight handle to an existing sandbox (running or stopped). Obtained viaSandbox.get() or Sandbox.list(). Provides status, configuration, and lifecycle control without an active connection to the guest agent. Call .start() or .connect() to upgrade to a full Sandbox.
| Property / Method | Type | Description |
|---|---|---|
| configJson | string | Raw JSON configuration |
| connect() | Promise<Sandbox> | Connect to a running sandbox |
| createdAt | number | null | Creation timestamp (ms since epoch) |
| kill() | Promise<void> | Force terminate |
| metrics() | Promise<SandboxMetrics> | Point-in-time resource metrics |
| name | string | Sandbox name |
| remove() | Promise<void> | Delete sandbox and state |
| start() | Promise<Sandbox> | Start in attached mode |
| startDetached() | Promise<Sandbox> | Start in detached mode |
| status | SandboxStatus | Current status |
| stop() | Promise<void> | Graceful shutdown |
| updatedAt | number | null | Last update timestamp (ms since epoch) |
SandboxInfo
Summary information about a sandbox, returned bySandbox.list().
| Field | Type | Description |
|---|---|---|
| configJson | string | Raw JSON configuration |
| createdAt | number | null | Creation timestamp |
| name | string | Sandbox name |
| status | string | Current status |
| updatedAt | number | null | Last update timestamp |
SandboxMetrics
Point-in-time resource usage snapshot.| Field | Type | Description |
|---|---|---|
| cpuPercent | number | CPU usage as a percentage |
| diskReadBytes | number | Total bytes read from disk since boot |
| diskWriteBytes | number | Total bytes written to disk since boot |
| memoryBytes | number | Current memory usage in bytes |
| memoryLimitBytes | number | Memory limit in bytes |
| netRxBytes | number | Total bytes received over the network since boot |
| netTxBytes | number | Total bytes sent over the network since boot |
| timestampMs | number | When this measurement was taken (ms since epoch) |
| uptimeMs | number | Time since the sandbox was created (ms) |
SandboxStatus
| Value | Description |
|---|---|
'crashed' | VM exited unexpectedly |
'draining' | Graceful shutdown in progress |
'running' | Guest agent is ready |
'stopped' | VM shut down; can be restarted |