sbx env exec
Experimental
This command is experimental.
Experimental features are intended for testing and feedback as their functionality or design may change between releases without warning or can be removed entirely in a future release.
Description
Run COMMAND in the sandbox declared in sbxenv.yaml. The sandbox must already exist (see "sbx env create" and "sbx env run"); a stopped sandbox is started first.
Arguments before -- are environment-file paths, following the same rules as
the other "sbx env" subcommands: each PATH may be a directory (the file is
-- every positional
argument forms the command and the environment file is read from the current
directory.
A directory PATH selects sbxenv.yaml; a file PATH selects that file. With no PATH, ~/.sbxenv.yaml supplies shared defaults when present. Explicit PATHs skip those defaults. Later files override earlier values; lists such as ports and mcp.servers are concatenated.
Flags match the behavior of "sbx exec".
Exit status is that of the command. sbx exits 125 if it could not run the command, for example because the sandbox does not exist. A missing command exits 127, unless a cloud backend reports it as an error rather than a status, which exits 125.
Options
| Option | Default | Description |
|---|---|---|
-d, --detach | Detached mode (not supported) | |
--detach-keys | Override the key sequence for detaching a container | |
-e, --env | Set environment variables | |
--env-arg | experimental Value for an argument the environment file declares, as name=value (can be repeated) | |
--env-args-file | experimental File of name=value environment arguments, one per line (can be repeated); --env-arg overrides | |
--env-file | Read in a file of environment variables | |
-i, --interactive | Keep STDIN open even if not attached | |
--name | Name for the sandbox, overriding 'name:' in sbxenv.yaml and the derived <agent>-<directory> (every 'sbx env' command addressing this environment needs the same value) | |
--privileged | Give extended privileges to the command | |
-t, --tty | Allocate a pseudo-TTY | |
-u, --user | Username or UID (format: <name|uid>[:<group|gid>]) | |
-w, --workdir | Working directory inside the container |
Global options
Examples
# Run a command in the environment declared in the current directory
sbx env exec go test ./...
# Open a shell
sbx env exec -it -- bash
# Run against explicitly merged environment files
sbx env exec sbxenv.yaml override.yaml -- npm test
