Skip to main content
Devbox operations distinguish command results from operation failures. Use operation options to cancel or time out work, and catch typed SDK or Connect errors when an operation cannot produce its normal result.

OperationOptions

Devbox methods that perform remote work accept signal and timeoutMs, either directly or through a method-specific options type.
AbortSignal
Cancels the operation when the signal is aborted. An already-aborted signal prevents the operation from starting.
number
The operation’s timeout budget in milliseconds.
For connection-backed operations with multiple phases, such as activating a stopped Devbox and then connecting to it, timeoutMs must be finite and non-negative and establishes one deadline shared by all phases. It is not reset after activation or connection. A timeout rejects with DevboxTimeoutError. Resource RPCs pass the timeout to Connect and can instead reject with a ConnectError whose code is DeadlineExceeded.

Example

Set a 30-second budget for activation, connection, and command execution:
Abort an operation from application code:
When a connection-backed operation is aborted, it rejects with signal.reason if it is an Error. Otherwise it rejects with an Error whose name is "AbortError". Cancellation is not represented by a DevboxError subclass. See Use interactive terminals for terminal-specific signal behavior.

Command results and rejected operations

exec() and shell() resolve with an ExecResult when the remote command runs, including when it exits non-zero. Check exitCode, signal, and error instead of relying on catch for command failure.
The promise rejects when the operation itself fails, including invalid input, abort, timeout, RPC or gateway failure, or an incomplete service response. fs.copy() and recursive fs.remove() run commands internally and reject with an ordinary Error when those helper commands fail. See Run commands for the complete ExecResult fields.

ConnectError

Namespace API failures surface as ConnectError from @connectrpc/connect. Inspect its Connect code for programmatic handling. Agent command DeadlineExceeded errors are converted to DevboxTimeoutError; other RPC deadline failures can remain ConnectError instances.

DevboxError

Base class for errors created by the Devbox SDK. Catch it to handle any SDK-level Devbox failure while allowing abort errors and ConnectError to follow separate paths.

DevboxTimeoutError

The operation exhausted an SDK-managed timeoutMs budget. This can happen during a connection-backed operation’s activation, connection, handshake, or remote work, including command execution.
number
The configured timeout in milliseconds when that value is available at the point where the error is created.

DevboxGatewayError

The Devbox gateway or display endpoint rejected a connection with an HTTP error. The status code is available for logging or conditional handling. Authentication failures commonly use status 401 or 403 and are not retried by the connection manager.
number
required
The HTTP response status returned by the gateway.

DevboxDisplayUnavailableError

The Devbox does not expose the VNC display service. This appears when using devbox.display with a Devbox that has no graphical display.

IncompleteResponseError

The service response omitted a field required to complete an operation. It can appear when a create, get, update, or lifecycle response lacks its Devbox value, or when a command stream ends without a final result.

ImageOptimizationError

Image optimization reported failure, or its event stream ended before reporting completion.

Catch Devbox failures

Import Devbox error classes from @namespacelabs/sdk/devbox. Check specific classes before their DevboxError base class.
Handle aborts separately when cancellation is expected:

Run commands

Interpret command exit codes and output.

Use interactive terminals

Open, close, and wait for terminal sessions.

Authenticate with Namespace

Configure credentials and handle authentication failures.
Last modified on August 26, 2026