Skip to main content

TypeScript SDK (@voidrun/sdk)

The official Node.js client for VoidRun: ESM-first, TypeScript types generated from OpenAPI, and API names aligned with the Python SDK. Use this page for a structured reference; the package README and repo examples/ stay the source for exhaustive snippets.

npm

Package and versions

Hub

Auth, base URL, REST overview

Requirements and install

  • Node.js 18+ (ESM); Node 20+ recommended for tsx examples
  • TypeScript 5.x when compiling from source

Configuration

VoidRun requires an API key. If you omit apiKey, the client reads process.env.VR_API_KEY (empty → throws). Base URL defaults to the packaged BASE_PATH (same host as OpenAPI servers). You override it only for self-hosted deployments: see below.
Hosted VoidRun: you only need VR_API_KEY. For self-managed APIs, set VR_API_URL (or baseUrl) to your deployment’s root (include /api if that is how the server is mounted). See Self-hosted deployments.

Create sandbox (createSandbox)

vr.createSandbox(options) calls POST /sandboxes. The request body matches OpenAPI CreateSandboxRequest (see API Reference → Sandboxes → Create sandbox).

Options

* name is required on the REST contract; the TypeScript client supplies a generated name when you omit it.

Organization and user identity

Every POST /sandboxes call is authenticated with X-API-Key. The platform resolves organization and user from that key:
  • orgId — the organization the API key belongs to.
  • userId — the user associated with the key (typically the user who created the key).
When you omit orgId and userId (recommended), the API uses those resolved values. The TypeScript client sends empty strings by default, which the service treats as “use the key’s org and user.” When you pass orgId and/or userId, the API validates that:
  1. The API key is authorized for the given orgId (the key must belong to that organization).
  2. The given userId is related to that organization (owner or member).
If the key, user, and org are not consistent, the request fails (for example 403 Forbidden). You cannot create a sandbox under another org or as an unrelated user.
The VoidRun MCP tool create_sandbox accepts the same CreateSandboxRequest fields as REST and the SDKs (including mem, orgId, userId, envVars, autoSleep, sync, region, refId). See VoidRun MCP.
Returns a VRSandbox instance. Use sandbox.remove() (or vr.removeSandbox(id)) when you are done. For long CI-style jobs that must not idle-pause, pass autoSleep: false (see GitHub Actions example).

Client: VoidRun

Pagination meta: total, page, limit, totalPages (camelCase).
Label filters use AND semantics: a sandbox must match every supplied pair, but may contain additional labels.

Sandbox lifecycle

On the sandbox instance:
  • sleep() — snapshot the VM (status becomes snapshotted)
  • wake() — restore from snapshot back to running
  • start() — recovery boot for snapshotted / killed / error sandboxes
  • update({ autoSleep }) — PATCH /sandboxes/{id}; currently autoSleep only
  • stop() / pause() — aliases of sleep() (the API has no /stop or /pause route)
  • resume() — alias of wake()
  • remove() — delete the sandbox on the API
  • info() — returns Promise<this> (refreshed view)
Any API call against a snapshotted sandbox transparently wakes it, so you usually don’t need to call wake() yourself. See Sandbox lifecycle for the full state machine.

Public URLs

Publish ports at create time or update them later, then fetch the public URLs from the sandbox instance:
See Public URLs for the full behaviour, including cold-wake on the first request.

Shell execution (exec)

Non-streaming exec returns an ExecResponse. Read stdout/stderr/exit code from result.data (ExecResponseData):
Options on the request object: command, cwd, env, timeout (seconds).

Streaming

Pass a second argument with handlers, or use execStream:

Code interpreter (runCode)

runCode returns CodeExecutionResult: fields live at the top level (no .data wrapper):
Languages commonly supported: python, javascript, typescript, node, bash, sh (confirm on your deployment). Streaming callbacks (onStdout, onStderr, …) are supported via the options object.

Background commands

sandbox.commands uses positional arguments for run:
connect(pid, handlers) attaches to a process stream (onStdout, onStderr, onExit, onError). See Background commands for REST paths and concepts.

File system (sandbox.fs)

High-level operations include:
  • Write: createFile, uploadFile, uploadFileStream
  • Read: downloadFile, downloadFileStream, headTail
  • Manage: deleteFile, listFiles, statFile, createDirectory, moveFile, copyFile, changePermissions
  • Search / size: searchFiles, folderSize
  • Archives: compressFile, extractArchive
List responses often expose entries on result.data?.files (check types for your SDK version).

File watching

See File watching for the HTTP + WebSocket flow.

PTY (sandbox.pty)

  • Ephemeral: connect({ onData, onError }): temporary shell; sendInput, close.
  • Persistent: createSession() → use returned sessionId with connect({ sessionId, … }); sessions survive disconnect until deleted.
  • Helpers: runCommand(cmd, { timeout, prompt }), resize(cols, rows), list(), deleteSession(id).
See PTY and the npm README for full examples.

Error handling

API failures surface as thrown errors. Response bodies often include error and details: log both when debugging. The SDK may concatenate them into the error message.

Sub-clients summary

Examples and building

  • Runnable examples: see the @voidrun/sdk repository examples/ and scripts/run_all_examples.sh (uses tsx).
  • Build from source: npm run build (ESM + CJS outputs).

Next steps

Quickstart

End-to-end first sandbox

Code execution

Exec, interpreter, timeouts

Python SDK

Same concepts, snake_case API

API Reference

OpenAPI tab in this docs site