# run_command

The tool that runs a command in the foreground and returns its output once it exits.

| Tool | Description |
|---|---|
| `run_command` | Execute a binary with argv (argv-only schema, sandbox-wrapped via `go-pkg/sandbox`) in the foreground and return its combined output once it exits. A plain command with no shell metacharacter (`\|`, `&&`, `>`, `*`, `~`) is called directly, never wrapped; pipes, redirects and globbing need an explicit `['sh','-c','...']`, whose script is parsed and validated command-by-command — every binary must be a **bare command name**, and anything on `denied_command` is rejected outright. `['cd', ...]` is rejected: the work directory belongs to the user (set in the TUI with `Shift+P`), so a call passes absolute paths or `['sh','-c','cd <dir> && <command>']` instead — the agent `cd` that switched `Executor.WorkDir` was Removed in v1.3.0; `rm` is routed to the trash rather than deleting (inside the working directory it runs under `auto`, elsewhere in `$HOME` it asks, outside `$HOME` it needs the system password), and is rejected inside `sh -c`; on macOS `open` is rejected with a pointer to `open_file`, since the sandbox has no route to the app-launch service. Each call is capped at 30 min (`RUN_COMMAND_TIMEOUT`); a file watcher, a job likely over 5 minutes (`BACKGROUND_THRESHOLD_MIN`) or 跑完告訴我 / 背景跑 goes to `background_command`. Since v1.0.25 the sandbox keeps networking off by default: a command that has to reach a host (`git clone` / `fetch` / `pull` / `push`, `npm` / `pip install`, `go mod download`, `curl`) sets `network: true`, and such a call never counts as read-only, so it confirms under `safe` and runs without a prompt under `auto`. Since v1.5.0 the Command network switch (`command_network_disabled`, `/config` → Command network, enabled by default) can turn that off: a `network: true` call in `run_command` or `background_command` is then refused with `[Denied]` before any confirmation and told to retry with `network: false` only, and a `network: false` `run_command` that fails with output matching `configs/jsons/network_error.json` gets a note that it failed because Command network is disabled, so the agent does not retry it with `network: true` and tells the user the step needs network (since v1.5.1 the note is added to every failed `network: false` call and reads "if this is a network problem"). Since v1.3.2 a system package is installed through `run_command` itself: Linux → `['sudo','apt-get','install','-y','<pkg>']` (or dnf / yum / pacman / apk), macOS → `['brew','install','<pkg>']` with `sandbox: false`, never `sudo` with brew. Since v1.3.3 the manager comes from the system prompt's `Host OS` line, which also gives the OS version; `command -v` is the fallback only when that line names none. Commands on the read-only allowlist (`configs/jsons/read_only_command.json`, 532 entries since v1.3.3, 409 after `cd` left it in v1.3.0, merged with `read_only_command` from `config.json`) skip the confirm gate: since v1.0.25 the binary plus up to two following arguments are matched (`git status`, `docker ps`, `kubectl get`, `ls`, ...), and a match is cancelled when any argument is a sensitive path. The dedicated read-only command tool added in v1.0.23 (`run_command_readonly`, which ran in parallel) was removed in v1.0.25, and the short-lived `run_script` never shipped in a release; use `run_command`; since v1.3.3 calls that match the allowlist run concurrently, everything else serially. To write outside `$HOME` the call carries `write_paths`, which are bound in only after a password-backed approval. Since v1.5.0 `~/.config/agenvoy` is read-only inside the sandbox except its `download/`: listing it (or a path under it) in `write_paths` is refused with `[Denied]`, `rm` cannot move anything out of it, and skills change only through `write_skill`. Since v1.3.2 argv `['sudo','<binary>', ...]` is accepted: no sudo flags, no nested `sudo` / `su`, and the target must be a bare binary name not on `denied_command`; it raises a confirmation labelled `sudo: <cmd>` that always demands the system password (even in allow-all mode; allow rules never skip it), then runs as `sudo -n <binary> ...` outside the sandbox; since v1.3.11 cancelling it (here or in `background_command`) sends `SIGTERM` to `sudo`, which relays it to the root command, and `sudo` is killed only if it is still running after the 2-second `WaitDelay`. `sudo rm` deletes for real, while plain `rm` still moves to the trash. `sudo` inside `sh -c` is still rejected, with an error pointing to the argv form. Since v1.3.0 `sandbox: false` runs the command outside the sandbox with the user's full permissions, and `network` / `write_paths` are then ignored; it is meant for a command the sandbox blocked with a permission error that `network` or `write_paths` cannot fix (Homebrew needs it, since its own sandbox cannot nest), and every such call asks for the system password — allow rules and allow-all never skip that prompt (since v1.3.22 only a trusted Skill does), and a channel that cannot collect the password gets the call back unrun. When a sandboxed command fails with a permission error and no path outside `$HOME` can be granted through `write_paths`, the result appends advice that treats leaving the sandbox as the last resort (since v1.3.11; from v1.3.2 to v1.3.10 it said to re-run right away with `sandbox: false`): a connection or auth failure (`Permission denied (publickey)`, `could not resolve host`) → `network: true` or report the credential problem; a write → a path under the work directory or `write_paths`; a genuine system socket, device or service, or a root-owned target → `sandbox: false` or argv `['sudo', ...]`; otherwise report what was blocked and stop. Since v1.5.1 the hints are unified for `run_command` and `background_command`: every failed sandboxed call, and a successful one whose output reads as a network error or carries a permission marker, gets them appended in order — for a `network: false` call, "if this is a network problem, re-run with `network: true`" (or, while Command network is disabled, "tell the user to enable `/config` → Command network"); the `write_paths` hint for unbound paths outside `$HOME`; then "if the sandbox caused this, re-run with `sandbox: false`", which asks for the system password. The separate last-resort advice was Removed in v1.5.1. Since v1.3.11 streamed output and the result are secret-masked, and an argv containing a masked value from an earlier tool result is refused with `[Invalid]`; a command that needs a key reads it inside the same call (`['sh','-c','set -a; . ./.env; set +a; curl ...']`). Since v1.0.11 a file watcher is rejected before it starts: `--watch` / `--watch=...`, a `chokidar` binary, or an `npm` / `pnpm` / `yarn` / `bun` script that resolves to one — the package script is parsed out of `package.json` and followed up to 4 levels (5 before v1.1.2), through `sh -c` too, and since v1.1.2 a script already visited is not followed again — because `run_command` waits for the process to exit and a watcher never does. Since v1.3.1 the error sends the watcher to the background tool (`background_command` since v1.3.2) with `timeout_min`, or to a one-shot build |

`pkg_manage` was Removed in v1.3.2; use `run_command` with argv `['sudo', ...]` (Linux package managers) or `sandbox: false` (Homebrew) instead.
