Agent-Guard: Preventing Test Tampering and Unauthorized Actions
Description and use
Guard against test tampering and unsafe commands via agent-guard hooks, ensuring agents fix source code and avoid risky actions.
Problem
Agents can modify tests instead of fixing source code, leading to false positives and unsafe actions.
Outcome
The guards prevented a test from being altered to pass, blocked a push to a protected branch, and logged all actions, ensuring safer agent operations.
Workflow
- Install agent-guard-hooks and agent-guard via pip
- Configure denylist/allowlist in ~/.config/agent-guard/config.json
- Start agent session; hook snapshots SHA256 of all test and source files
- During session, agent attempts to modify tests or run risky commands
- Hook intercepts and blocks test changes if no source file changed
- Hook intercepts and blocks Bash commands matching denylist patterns
- Agent receives block notice and must correct its behavior
- Agent completes session only if all checks pass
Evidence
On SessionStart, the hook snapshots sha256 hashes of every test file and every source file in the project. On Stop, it diffs. If test files were modified or deleted while no source file changed, the stop is blocked:
A PreToolUse hook on Bash matches commands against a denylist of risky patterns and blocks before they run:
- Record date: 2026-10-01T19:25:44.007Z