# Sandbox

Which executions run in the OS sandbox, what it restricts, and the four code paths that call it.

Every `run_command` / `background_command`, script tool, `test_tool` and hook execution is wrapped by `go-pkg/sandbox`:

| Platform | Mechanism |
|---|---|
| Linux | bubblewrap (`bwrap`) |
| macOS | `sandbox-exec` |

Sandbox restrictions: no privileged execution, restricted filesystem write scope (writes only under `$HOME`; since v1.5.0 `~/.config/agenvoy` is read-only except `download/`), per-call network access, configurable CPU/memory limits.

Since v1.0.25 `run_command` (and, since v1.3.1, the background variant; `run_command_background` was renamed `background_command` (Removed in v1.3.2)) runs with networking denied (`NetworkDeny`) unless the call sets `network: true`, which switches that one call to `NetworkAllow`; a networked call never counts as read-only, so it confirms under `safe` and runs without a prompt under `auto`. Since v1.3.0 `sandbox: false` passes `AllowAll`, so that one call runs with no sandbox at all, only after the user's system password is verified. Since v1.3.2 an argv `['sudo', '<binary>', ...]` also runs outside the sandbox, as `sudo -n <binary> ...` on the sudo ticket, once its password-backed `sudo: <cmd>` confirmation is approved. Since v1.5.0, with the **Command network** switch off (`command_network_disabled`), `network: true` is refused before confirmation (see [Command Execution](/security-commands)). Script tools (`script_*`, `ext_*`) and `test_tool` call `sandbox.Wrap` with no option, so they keep network access. Hooks do too unless the **Hook network** switch is off (`hook_network_disabled`, since v1.5.0), which runs them with `NetworkDeny`. The networked `run_script` tool that briefly existed during v1.0.25 development never shipped in a release; use `run_command` with `network: true`.

## Four callers, one entry point

The sandbox has exactly four call paths, all calling `sandbox.Wrap(ctx, binary, args, workDir, opt)` directly:

1. `run_command` and `background_command` — arbitrary user-issued commands, sharing one `runCommand` path (`internal/tools/command/runCommand.go`, `runCommandBackground.go`)
2. `toolAdapter` execute (`internal/runtime/toolAdapter/ececute.go`) — script-tool extensions (`script_*`, `ext_*`)
3. `test_tool` — trial runs of a script tool's `script.py` (60 s limit)
4. Hooks (`internal/agents/exec/hook/call.go`) — lifecycle hook scripts, 30 s limit (`HOOK_TIMEOUT`); see [Hooks](/hooks-overview)

Since v1.3.0 the command tools and `test_tool` start the wrapped process with `sandbox.Run` (go-pkg v0.13.17), which kills the process group after the command exits; the script adapter and hooks start and wait on the process themselves. There is no wrapper layer between callers and `sandbox.Wrap`. Adding behavior (e.g., new resource limits) means contributing to `go-pkg/sandbox`, not adding shims in agenvoy.
