Skip to main content
Run non-interactive commands with exec() or shell(). Choose between structured arguments and shell evaluation based on the command you need to run.
Command operations start a stopped Devbox automatically. Commands run with exec() and shell() are retained with their output and can be inspected later with devbox logs.

exec()

Use exec() to pass an executable and its arguments without invoking a shell. Arguments are passed literally, so shell expansion, pipelines, redirects, and environment-variable interpolation do not apply.

Example

Run a command and inspect its result:

API reference

Arguments and options

readonly string[]
required
The executable followed by its arguments. The array must contain at least one item.
ExecOptions
Options for the command.
When cwd is omitted, the command runs in the Devbox’s default directory. If the Devbox checks out a repository during creation, that directory may not exist until the checkout completes. Pass an explicit cwd when running a command immediately after creation.

Return value

exec() resolves with an ExecResult after the command finishes.
number | null
required
The command’s exit code, or null when no exit code is available.
string | null
required
The signal that ended the command, or null when no signal is available.
string
Agent-reported failure detail, such as a command-not-found message.
string
required
The complete standard output decoded as UTF-8.
string
required
The complete standard error decoded as UTF-8.
A non-zero exit code does not reject the promise. Check exitCode to determine whether the command succeeded. The promise rejects for failures such as an invalid request, an aborted operation, a timeout, or a transport error.

More examples

Pass arguments containing spaces

Arguments containing spaces remain single arguments.

Stream command output

Stream output while retaining it in the returned result.

shell()

Use shell() when a command requires shell syntax such as pipelines, redirects, variable interpolation, or multiple statements.

Example

Run a script that chains two commands, then print its standard output:

API reference

Arguments and options

string
required
The script to evaluate with the Devbox shell.
ShellOptions
All ExecOptions, plus the shell property.

Return value

shell() returns the same ExecResult as exec(). A non-zero exit code resolves normally and must be checked by the caller.

More examples

Set the working directory and environment variables

Use a specific shell

Choose between exec() and shell()

Use interactive terminals

Open and control interactive terminal sessions.

Create and manage Devboxes

Create a Devbox and control its lifecycle.

Handle errors and timeouts

Cancel operations and handle SDK failures.
Last modified on August 26, 2026