@coreweave/cwsandbox TypeScript client creates and manages CoreWeave sandboxes. Follow this guide to create a client, run a sandbox command, and handle SDK errors. This guide and the API reference cover version 1.0.0.
Prerequisites
Use Node.js 22 or later and an ECMAScript module (ESM) project. Save the examples as.mts files to run them with tsx.
Choose a credential from Choose and get credentials. The examples use serverless capacity. For CoreWeave Kubernetes Service (CKS) placement, enable a runner and use a CoreWeave API access token with a non-empty runnerIds array.
Install the SDK:
Create a client
Choose the entry point for your credential. Both factories return aSandboxClient. The root @coreweave/cwsandbox entry point exports types, constants, and errors. Create clients through /wandb or /node.
Save the code from your tab as a sandbox-client.mts file beside the other example files. It selects authentication and exports the client. The credential stays in your environment.
- Forge API key
- CoreWeave API access token
Replace To select a Forge team, set
[WANDB-API-KEY] with your Forge API key:sandbox-client.mts
WANDB_ENTITY. For explicit options, see Forge client factories.Run a command
For work that should stop when its callback finishes, usewithSandbox(). It waits for sandbox readiness before calling the callback and stops the sandbox after the callback returns or throws.
hello.mts
Hello! and stops the sandbox.
The ./sandbox-client.mjs import resolves to the local sandbox-client.mts file when you run with tsx or compile with TypeScript.
commands.run() buffers standard output (stdout) and standard error (stderr) and returns a ProcessResult with exitCode. For streaming output, use commands.start().
To keep the sandbox across operations, use client.create(), then stop it in a finally block. See the sandbox lifecycle reference.
Handle errors
UseisCWSandboxError() to narrow an unknown error and inspect its code:
check: true, a nonzero command exit raises CWSandboxExecutionError. For the error hierarchy and available metadata, see Errors.
API reference
The reference preserves the published declarations, including method overloads, parameter and return types, optional fields, and inherited types. SDK comments include reviewed corrections.
For a Compose example, see Create a sandbox from TypeScript.