sbx exec
Description
Execute a command in a sandbox. If the sandbox is stopped, it is started first. Or — with --cloud — the cloud sandbox ID (sbx_*) or name from "sbx --cloud ls".
Flags match the behavior of "docker exec", except detached exec (-d/--detach) is not supported. Some flags (-d, --user, --privileged) are not supported with --cloud and are rejected rather than silently ignored. --detach-keys applies only to an interactive (-i/-t) cloud 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-file | Read in a file of environment variables | |
-i, --interactive | Keep STDIN open even if not attached | |
--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
# Open a shell inside a sandbox
sbx exec -it my-sandbox bash
# Run as root
sbx exec -u root my-sandbox apt-get update
# Cloud: run a command in a cloud sandbox by ID or name
sbx --cloud exec -it sbx_abc123 bash
sbx --cloud exec -it claude/my-sandbox bash
