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
tsxexamples - 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
EveryPOST /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).
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:
- The API key is authorized for the given
orgId(the key must belong to that organization). - The given
userIdis related to that organization (owner or member).
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.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).
Sandbox lifecycle
On the sandbox instance:sleep()— snapshot the VM (status becomessnapshotted)wake()— restore from snapshot back torunningstart()— recovery boot forsnapshotted/killed/errorsandboxesupdate({ autoSleep })—PATCH /sandboxes/{id}; currentlyautoSleeponlystop()/pause()— aliases ofsleep()(the API has no/stopor/pauseroute)resume()— alias ofwake()remove()— delete the sandbox on the APIinfo()— returnsPromise<this>(refreshed view)
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:Shell execution (exec)
Non-streaming exec returns an ExecResponse. Read stdout/stderr/exit code from result.data (ExecResponseData):
command, cwd, env, timeout (seconds).
Streaming
Pass a second argument with handlers, or useexecStream:
Code interpreter (runCode)
runCode returns CodeExecutionResult: fields live at the top level (no .data wrapper):
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
result.data?.files (check types for your SDK version).
File watching
PTY (sandbox.pty)
- Ephemeral:
connect({ onData, onError }): temporary shell;sendInput,close. - Persistent:
createSession()→ use returnedsessionIdwithconnect({ sessionId, … }); sessions survive disconnect until deleted. - Helpers:
runCommand(cmd, { timeout, prompt }),resize(cols, rows),list(),deleteSession(id).
Error handling
API failures surface as thrown errors. Response bodies often includeerror 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/sdkrepositoryexamples/andscripts/run_all_examples.sh(usestsx). - 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

