AI coding agents can edit files, run shell commands, and touch infrastructure. One bad rm -rf, force-push, or docker compose down -v can wipe hours of work or production data.
| 1 | # Using agent-guard with Codex |
| 2 | |
| 3 | This documents a **generic** integration pattern for OpenAI Codex-style coding agents. It is not a built-in Codex feature. |
| 4 | |
| 5 | ## Check before exec |
| 6 | |
| 7 | When the agent proposes a shell command: |
| 8 | |
| 9 | ```bash |
| 10 | agent-guard check --json 'git push --force origin main' |
| 11 | ``` |
| 12 | |
| 13 | Parse JSON `decision` / `reason` / `risk`. Surface BLOCK/WARN to the user. |
| 14 | |
| 15 | ## Run through the guard |
| 16 | |
| 17 | ```bash |
| 18 | agent-guard run --allow-risk -- pytest -q |
| 19 | ``` |
| 20 | |
| 21 | Use `--allow-risk` only when the human intentionally accepts a WARN. It does **not** unlock BLOCK. |
| 22 | |
| 23 | ## Policy file |
| 24 | |
| 25 | Keep `.agent-guard.yml` in the repo (see `examples/agent-guard.yml`). Point Codex workspace instructions at: |
| 26 | |
| 27 | > All shell commands must pass `agent-guard check` or be executed via `agent-guard run -- …`. |
| 28 | |
| 29 | ## Limitations |
| 30 | |
| 31 | agent-guard analyzes command text. Obfuscated or multi-stage payloads may evade static rules. Treat it as a seatbelt, not a vault. |