Skip to main content
@boxrouter/sdk is a promise-based client with bundled type declarations. It supports Node.js 22.18 or later. Node.js 22.18 strips types from .mts files by default. Direct .mts examples that use await using need Node.js 24 or later. npm ls @boxrouter/sdk prints the version you have.

Install

Import the named exports from an .mjs file or a "type": "module" project; a .cjs file can require them. Your first sandbox is in the quickstart.

Configure the Client

Each setting comes from the option, then the environment variable, then the default. There is no timeout option. The client resends an API call only when the error says retry: safe, up to maxRetries times, with the same idempotency key. To bound an API request, pass a fetch that adds an abort signal. An aborted call throws RequestError; Recover from Errors says when resending is safe.

Close the Client

Client and sandbox handles support asynchronous disposal. await using closes the client and destroys the sandbox at the end of their scopes, even when the workload throws. The sandbox is disposed before the client. Disposing the client alone closes its local connection pool and leaves sandboxes running. Run .mts files that use await using directly with Node.js 24 or later. The syntax needs TypeScript 5.2 or later and the esnext.disposable library (or esnext) in tsconfig. See the TypeScript 5.2 release notes.
If both the workload and disposal fail, TypeScript’s async-disposal handling preserves both errors.

Handle Errors

A command that exits nonzero or reaches its timeout is a result: read exit_code and timed_out, because nothing is thrown. Pass { check: true } to throw CommandFailed for either. Save this example as errors.mts. It runs a command in a sandbox that does not exist and prints the error’s code and outcome:
A retry of check_outcome means BoxRouter cannot tell whether the call ran. Read the operation before resending (Recover from Errors has the steps), and quote requestId to support.

Where Each Task Lives

Next Steps

Find an SDK or CLI Call

The TypeScript call for each sandbox task.

Recover from Errors

When resending a failed call is safe.

Use the Python SDK

The same tasks in Python.