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.
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.
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()
Related documentation
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.