Skip to main content
devbox exec runs a command inside a Devbox without opening an interactive shell. Each run is recorded as an execution with its own ID, and its output is retained on the Devbox — so you can stream it live, or come back and read it later with devbox logs. This makes devbox exec a good fit for scripted and automated work: builds, test suites, migrations, and anything driven by a coding agent.

Running Commands

Run a command and stream its output back to your terminal.
When the command has flags of its own, add -- to separate the Devbox CLI arguments from the command that should run inside the Devbox:
When the command fails, devbox exec exits with a non-zero status.
Commands run as the devbox user with /workspaces as the working directory, and flags for devbox exec itself go before the Devbox name.If the Devbox is paused, it is resumed automatically before the command runs.
For interactive programs or piped input, use devbox ssh instead.

Detached Executions

Start a command and return immediately, leaving it running on the Devbox. Each detached execution has an ID, which is how you read its output later:
A detached execution keeps running after the CLI exits. A foreground execution, by contrast, is tied to your CLI session, so prefer -d for long-running work or when your connection might drop. However, a detached execution ends if the Devbox stops.
Use the printed ID with devbox logs to follow the output or collect it later. In a script, capture it as you start the command:
Detaching is a CLI feature. devbox.exec() always waits for the command to finish.

Reading Command Logs

Output from every execution is retained on the Devbox, so you can read it while a command is still running or long after it has finished. Retained output survives pause and resume, and is removed when the Devbox is deleted. Commands run through the SDK are retained in the same way. The SDK has no log-reading API, so use the CLI commands below to inspect them.

Streaming Logs

Stream the output of an execution by ID:
devbox logs first replays the output that has already been captured, then follows the live output, and returns once the execution completes. This works for executions that have already finished too, which is how you re-read the results of an earlier run.

Listing Executions

List the executions retained on a Devbox:
The Status column is running while the command is still going, then completed, or failed with the command’s exit code. For scripting, use JSON output:
error and exit_code are only present when the execution failed, and completed_at is unset while it is still running. Executions are listed in the order they started.

Interactive Access

devbox exec runs commands non-interactively: no terminal is allocated, and standard input is not forwarded. When a task needs either, use one of these instead.
devbox ssh opens an interactive shell, and can also run a single command with devbox ssh [command]:
Because it allocates a terminal and forwards standard input, it handles interactive programs and piped data:

Choosing an Approach

  • Use devbox exec for scripted and automated runs, and whenever you want the output kept.
  • Use devbox ssh for interactive work, or when you need to pipe data into a command.
  • Use a Session for a long-lived interactive process, such as a dev server you want to reattach to.

Next Steps

Sessions

Persistent terminal sessions that survive disconnections.

Remote Development

SSH access and SSH config for a Devbox.

Agent Skills

Drive Devboxes from AI coding agents.
Last modified on September 25, 2026