Skip to main content
Use the SDK when a program needs to create Devboxes and run work in them: test runners that fan out across machines, agent harnesses that need an isolated sandbox per task, or internal tooling that provisions environments for your team. This page takes you from an empty project to a script that creates a Devbox and runs a command in it.

Getting Started

1

Authenticate with Namespace

The SDK has no login of its own. It reads the credential written by the Devbox CLI, so install the Devbox CLI and log in once:
For automated workloads, use workload identity federation instead. Applications running inside a Namespace workload already receive a credential and need no setup.
2

Install the SDK

Add the SDK to your project:
The Devbox API lives at @namespacelabs/sdk/devbox. The package root re-exports the same API.
3

Create a client

The client holds the connection to Namespace. createDevboxClient() resolves the credential from step 1 automatically when tokenSource is omitted.
See Create a client for configuration options.
4

Create a Devbox

devboxes.create() provisions a Devbox and returns a handle you operate on. Devboxes start by default, and the call waits for the Devbox to become ready.
Setting repository checks out that repository in the Devbox, which requires a connected GitHub organization.
Use devboxes.get() to get a handle for a Devbox that already exists:
5

Run a command

devbox.exec() runs a command in the Devbox and resolves once it finishes, giving you its output and exit code.
A non-zero exit code resolves normally rather than throwing, so check exitCode yourself.
6

Close the client

Close the client when you are finished with it to release its cached connections.
Closing the client does not delete the Devbox. Call devbox.delete() to remove it, or create it with ephemeral: true so its instance and storage are discarded when it stops.

The complete script

The steps above assemble into one file:

Other ways to run commands

exec() covers most cases. Use one of these when it does not.
devbox.shell() runs a script through the Devbox’s configured shell. Use it for pipes, redirects, variable expansion, or chained commands.
See Run commands for when to choose exec() over shell(), and Use interactive terminals for the full terminal interface.

TypeScript SDK reference

The reference documents the complete SDK surface, starting with installation and a first Devbox.

Devboxes

Creation options and lifecycle operations.

Commands

exec(), shell(), their options, and their results.

Authentication

Workload identity federation, local credentials, and token sources.

Set this up with a coding agent

Hand your agent the prompt below instead of following the steps above. It installs the Namespace devboxes agent skill, which covers the CLI setup, then points the agent at the SDK reference so it writes against the current API. You will need to complete the login in your browser when the agent reaches that step.
Agent Prompt
To install the skill yourself, or to install it globally rather than per project, see Agent Skills.

Next steps

Devbox CLI

Create and connect to Devboxes from your terminal.

Agent Skills

Let a coding agent create and drive Devboxes for you.

Blueprints

Reusable Devbox configurations.
Last modified on September 16, 2026