Last week I deleted the JavaScript implementation of agent-runner and rewrote it in Go. The agent loop ported cleanly. The interesting part was the tool layer, because that is where an agent stops being a demo.
In the JS version, run_command called exec() and let the shell sort it out. That is fine when the only thing running it is you, on your own machine, watching the output. It is not fine the moment the loop runs unattended against a repo you care about. A model that can reach a shell can do anything your user can do, and it will get there by accident long before it gets there on purpose.
So the Go port puts the whole safety story in three boring places.
1. There is no shell to reach
The command string is split into argv by hand. When the tokenizer meets a character a shell would interpret, it refuses instead of quoting it:
const shellChars = ";&|<>$`*?()[]{}~!\\" // inside tokenize() case strings.ContainsRune(shellChars, ch): return nil, fmt.Errorf("shell syntax is not supported: %c", ch) A pipe is not a filename, and pretending otherwise is how a "safe" runner ends up executing the second half of a command someone else wrote. Refusing is the honest answer. There is no globbing either, so *.go is just a string that no allowlisted command will accept.
2. An allowlist entry has to promise flags, not just a binary
The first version of the allowlist was a set of names: ls, cat, wc, git. That is not a safety boundary. Plenty of ordinary binaries are launchers if you are allowed to pass the right argument:
node -e "..."python3 -c "..."git -c core.pager='...' log
None of those need a shell. All of them run arbitrary code. So every entry in the policy declares exactly which flags it accepts, and for a multiplexer like git, which subcommands and which flags under each:
var Commands = map[string]Command{ "ls": {Flags: []string{"-1", "-a", "-A", "-l", "-h", "-la", "-al", "-lah"}}, "cat": {}, "wc": {Flags: []string{"-l", "-w", "-c", "-m"}}, "git": {Subcommands: map[string][]string{ "status": {"--short", "--porcelain", "-s"}, "log": {"--oneline", "--stat", "--decorate", "-n", "--max-count"}, "diff": {"--stat", "--name-only", "--cached"}, "show": {"--stat", "--oneline"}, }}, } ``` The check is exact, including `--flag=value` forms where the value gets its own validation. When it fails, the error names the binary and the argument. That matters: the model reads the refusal as the observation for that step and re-plans. A vague "denied" makes it retry the same thing with a different spelling. `git: argument not allowed: -c` makes it stop. `cat` with no flags is deliberate. `cat` on `/dev/urandom` was never reachable anyway, since absolute paths are refused, and `read_file` covers the useful case with a 2 MiB cap. ## 3. Paths go through their deepest existing ancestor Rejecting `..` and absolute paths is the easy half. The half that bites is symlinks: `link/secret` looks like a relative path and resolves somewhere else. So a path is resolved by walking up to the deepest component that exists, calling `EvalSymlinks` on that, and rejoining the rest before checking that the result is the root or below it. If nothing resolves, the path is refused rather than guessed at. Same rule for the git operands, with one exception: `rev:path` forms name objects inside the repository, not files on disk, so they skip the filesystem check. ## What this costs You lose pipes and redirects. There is no `grep -r`, no `go test ./... | tail`. In practice the loop does fine: `git log --oneline -n 20`, `wc -l`, then `read_file` on what looks interesting. If a task genuinely needs more, you add an entry to the map on purpose, which is the point. The allowlist is a maintenance burden and I would rather carry it than carry a shell. Eleven tests in `internal/tools` are named after the attacks, not the functions: `TestRefusesShellChaining`, `TestRefusesLauncherFlags`, `TestRefusesSymlinkEscape`. CI runs `gofmt -l`, `go vet`, and `go test -race ./...`. The default entry point runs against a deterministic mock planner, so a run is reproducible without an API key. Runtime is about 1,300 lines of Go now. Repo: [marcus-beauregard/agent-runner](https://github.com/marcus-beauregard/agent-runner). 