Sandbox VMs with instant time-travel snapshots
npm install opensandbox
Or link locally during development:
# In the opensandbox repo
npm link
# In your project
npm link opensandbox
import { Client } from "opensandbox"
// Initialize with your API key
const client = new Client("ws_your_api_key")
// Create a sandbox VM
const result = await client.create("my-sandbox")
if (!result.success) throw new Error(result.error)
const { sandbox } = result
// Run commands (auto-snapshots after each)
const cmd = await sandbox.run("echo 'hello world'")
if (cmd.success) {
console.log(cmd.stdout) // "hello world\n"
console.log(cmd.snapshot) // "cmd_1702147200000"
}
// Time travel to any snapshot
const snaps = await sandbox.snapshots()
if (snaps.success) {
await sandbox.restore(snaps.snapshots[0].snapshot_name)
}
// Cleanup
await sandbox.destroy()
The main entry point. Manages sandbox VMs.
Represents a single VM instance. Run commands, manage snapshots, and time-travel.
All methods return discriminated unions for type-safe error handling.
| Field | Type | Description |
|---|---|---|
| success | boolean | Whether command succeeded |
| stdout | string | Standard output (on success) |
| stderr | string | Standard error (on success) |
| exitCode | number | Exit code (on success) |
| snapshot | string | Snapshot name (on success) |
| error | string | Error message (on failure) |
| Field | Type | Description |
|---|---|---|
| id | number | Snapshot ID |
| vm_name | string | Parent VM name |
| snapshot_name | string | Unique snapshot identifier |
| command | string | null | Command that created this snapshot |
| created_at | string | ISO timestamp |
| Field | Type | Description |
|---|---|---|
| id | number | VM ID |
| name | string | VM name |
| status | string | Current status (e.g. "running") |
| agent_port | number | Agent communication port |
| ssh_port | number | SSH port |
| agentHealthy | boolean | Whether agent is responding |
| created_at | string | ISO timestamp |