TypeScript
Install the TypeScript SDK and learn how it handles cleanup, cancellation, and errors.
npm install dvm-runPublished as dvm-run on npm: ES modules only, built-in types, Node 22.12
or newer, zero dependencies. Includes the dvm-run CLI
(Getting in).
Create and end a sandbox
Section titled “Create and end a sandbox”Sandbox.create(image, options) resolves once the sandbox runs (or has
exited). Options: command, entrypoint, cpus, memoryMib, seed,
env, name, network, allow, apiKey, apiUrl, and signal.
Declare sandboxes with await using. When the scope exits:
- a session (a sandbox accepting commands) closes its input, and the scope waits for exit;
- a paused sandbox or one-program sandbox is stopped;
- an ended sandbox is left unchanged.
await using requires a runtime that supports it, such as Node 24. On Node
22, call end() or stop() in a finally block, or call
sandbox[Symbol.asyncDispose]() there. An unended sandbox keeps running.
Call Sandbox.connect(sandboxId) to attach to a sandbox created elsewhere.
Bytes and results
Section titled “Bytes and results”run and Command.wait() resolve to a CommandResult with exitCode,
stdout, and stderr (Uint8Array). File contents are also Uint8Array.
A command’s exit code is never an error.
IDs, offsets, and seeds are JavaScript numbers kept below 253.
Cancel a call
Section titled “Cancel a call”Every call takes an AbortSignal via signal. Aborting rejects the call
without undoing work already sent. Aborting a command’s wait leaves the
command running: signal it to end it. Aborting Sandbox.create during
startup stops the sandbox.
const server = await sandbox.start(["sleep", "600"]);try { await server.wait({ signal: AbortSignal.timeout(5_000) });} catch (error) { if (!(error instanceof DOMException && error.name === "TimeoutError")) throw error; await server.signal(9); console.log((await server.wait()).exitCode);}Errors
Section titled “Errors”All errors inherit from DvmError. HTTP errors throw ApiError (status,
reason), with subclasses for 400, 401, 404, and 409. Calling an ended
sandbox throws SandboxEndedError, or SandboxFailedError (with reason)
if dvm or the platform ended it. Connectivity errors throw NetworkError.
Sandbox-side rejections throw plain DvmError with the message. See
Errors.
try { await using sandbox = await Sandbox.create("alpine:3.20", { command: ["true"], cpus: 64 }); await sandbox.wait();} catch (error) { if (error instanceof InvalidRequestError) console.log(error.status, error.reason); else if (error instanceof SandboxFailedError) console.log("dvm ended it:", error.reason); else if (error instanceof ApiError && error.status === 402) console.log("out of credit:", error.reason); else if (error instanceof ApiError && error.status === 403) console.log("not let in yet:", error.reason); else throw error;}Where next
Section titled “Where next”- Sessions: run commands and transfer files.
- TypeScript reference: every class and method.
- npm and source.