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.
Give AI agents freedom to code — without giving them unrestricted access.
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.
agent-guard is a small, local-first security layer that sits between an AI agent and your system. It evaluates risky operations and returns a clear decision:
AI Agent
↓
agent-guard
↓
ALLOW / WARN / BLOCK
↓
System
It is not an AI assistant. Decisions are deterministic, offline, explainable, and auditable. No LLM. No network. No telemetry.
.env, keys, credentials (values never printed).agent-guard.yml with modespip install agent-guard
git clone https://github.com/gitrabbit/agent-guard.git
cd agent-guard
python -m venv .venv
# Linux/macOS
source .venv/bin/activate
# Windows
# .venv\Scripts\activate
pip install -e ".[dev]"
agent-guard init
agent-guard check "git reset --hard HEAD"
agent-guard scan
agent-guard run -- npm test
agent-guard check "rm -rf ./src"
BLOCK
Risk: CRITICAL
Reason: Recursive deletion inside the source directory.
agent-guard check "rm -rf /"
Exit code: 20 (BLOCK)
agent-guard check "git push --force origin main"
BLOCK
Protected branch force-push detected.
agent-guard check "git reset --hard HEAD"
WARN
Risk: HIGH
Reason: This operation can permanently discard uncommitted changes.
agent-guard check "docker compose down -v"
BLOCK
Docker volumes may contain persistent application data.
agent-guard check "cat .env"
BLOCK
Sensitive file access detected.
Target: .env
agent-guard check "curl -X DELETE https://production.example.com/api/users/1"
BLOCK
agent-guard check "git status"
ALLOW
agent-guard run -- git reset --hard HEAD
Interactive WARN prompt (default N). Non-interactive sessions deny WARN unless --allow-risk is set. BLOCK is never overridden by --allow-risk.
agent-guard check --json "rm -rf ./"
{
"decision": "BLOCK",
"risk": "CRITICAL",
"operation": "DIRECTORY_DELETE",
"rule_id": "filesystem.recursive_delete",
"reason": "...",
"target": "./"
}
agent-guard check --file-operation delete ./src
agent-guard run --allow-risk -- git reset --hard HEAD
Still cannot run:
agent-guard run --allow-risk -- rm -rf /
# → BLOCK, never executed
agent-guard init creates .agent-guard.yml in the project root (relative paths only — never hardcodes your absolute home path):
version: 1
project_root: .
mode: default # default | strict | permissive
protected_paths:
- .env
- .env.*
- .git/
- ~/.ssh/
- ~/.aws/
- secrets/**
writable_paths:
- src/
- tests/
- docs/
protected_branches:
- main
- master
- production
- prod
network:
protected_hosts:
| Mode | Behavior |
|---|---|
default | Balanced developer protection |
strict | More WARN/BLOCK (HIGH WARN → BLOCK) |
permissive | Softer for non-CRITICAL; CRITICAL stays blocked |
Decision precedence when multiple rules match: BLOCK > WARN > ALLOW.
List built-in rules:
agent-guard rules
agent-guard rules --json
Categories include:
| Category | Examples |
|---|---|
destructive_filesystem | rm -rf, Remove-Item -Recurse, shutil.rmtree |
destructive_git | reset --hard, clean -fdx, rebase |
protected_branch_force_push | git push -f to main/master/prod |
secret_access | .env, PEM keys, credential files |
docker_volume_delete | compose down -v, volume rm, prune -a |
database_destructive | DROP, TRUNCATE, FLUSHALL, dropDatabase |
production_network | DELETE/PUT to production hosts |
shell_chain_destructive | && / ; chaining signals |
| Score | Level |
|---|---|
| 0–19 | LOW |
| 20–49 | MEDIUM |
| 50–79 | HIGH |
| 80+ | CRITICAL |
Rules may explicitly override the calculated band (e.g. rm -rf / is always CRITICAL/BLOCK).
| Decision | Meaning | Typical exit |
|---|---|---|
| ALLOW | Safe to proceed | 0 |
| WARN | Risky; confirm or --allow-risk | 10 |
| BLOCK | Do not execute | 20 |
Runtime/config errors use exit code 30.
command / file operation
│
▼
normalize ──► parse ──► detect (rules)
│
▼
classify risk
│
▼
evaluate policy
│
▼
ALLOW / WARN / BLOCK
Extension-friendly seams (MVP stays simple): policy provider, rule registry, decision engine, execution backend (shell=False subprocess).
Future surfaces can share the same engine:
agent-guard
│
┌───────────┼───────────┐
▼ ▼ ▼
CLI MCP Agent API
│ │ │
└───────────┼───────────┘
▼
Policy Engine
agent-guard is a policy enforcement layer, not a kernel-level sandbox.
run: evaluates before subprocess.run(..., shell=False)checkDesign for stronger enforcement later (MCP hooks, OS sandboxing, snapshots) without rewriting the policy core.
There is no native plugin claimed for Claude Code, Codex, Cursor, or OpenCode in this MVP. Use the CLI as a gate:
Agent tool call (bash / shell)
↓
agent-guard check|run -- <command>
↓
decision (exit code + text/JSON)
Patterns:
agent-guard check "..." and respects BLOCK/WARNagent-guard run -- <cmd>--json for structured policy resultsSee examples/ for Claude Code, Codex, and shell wrapper notes.
agent-guard check --json "git push -f origin main"
Fields include: decision, risk, operation, rule_id, reason, target, suggestions, matched_policy, detected, score, findings.
JSON contains no ANSI codes and never includes raw secret values.
| Code | Meaning |
|---|---|
| 0 | ALLOW |
| 10 | WARN |
| 20 | BLOCK |
| 30 | Runtime / configuration error |
For check, the exit code reflects the security decision.
agent-guard check "command" # analyze only
agent-guard check --file-operation delete PATH
agent-guard run -- <command> # evaluate then execute
agent-guard run --allow-risk -- ... # override WARN only
agent-guard init # write .agent-guard.yml
agent-guard scan # project risk scan
agent-guard rules [--json]
agent-guard config [--json]
agent-guard version
agent-guard --debug ... # debug with redaction
pytest
pytest --cov=agent_guard --cov-report=term-missing
ruff check .
mypy src
src/agent_guard/rules/<category>.py@register_rule(RuleDefinition(...))list[Finding] — never execute commands, never print secretstests/rules/@register_rule(
RuleDefinition(
id="git.example",
category="destructive_git",
risk=RiskLevel.HIGH,
default_decision=Decision.WARN,
description="Example rule",
)
)
def rule_example(parsed: ParsedCommand, config: GuardConfig) -> list[Finding]:
return []
See CONTRIBUTING.md.
Possible future ideas (not implemented):
MIT. See LICENSE.