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:-- separates Devbox CLI arguments from the command that should run inside the Devbox. You need it whenever the command has flags of its own. For a bare command, you can leave it out:
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.devbox ssh instead.
Detached Executions
Pass-d to start a command and return immediately. The CLI prints the execution ID instead of waiting:
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.devbox logs to follow the output or collect it later. In a script, capture it as you start the command:
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.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: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 devbox ssh.
devbox ssh opens an interactive shell, and can also run a single command with devbox ssh [command]:
Choosing an Approach
- Use
devbox execfor scripted and automated runs, and whenever you want the output kept. - Use
devbox sshfor 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.