AI Code Guardrails
Prevent destructive operations from AI coding assistants. A CLI wrapper that intercepts dangerous commands before execution.
Works with Cursor, GitHub Copilot, Claude, ChatGPT, and any AI assistant that generates shell commands.
Features
- Shell Command Safety: Blocks
rm -rf /, chmod 777, disk formatting, and other dangerous shell operations
- SQL Injection Prevention: Detects
DROP TABLE, DELETE without WHERE, TRUNCATE, and other destructive SQL
- Git Protection: Prevents force pushes, hard resets, and accidental pushes to protected branches
- File System Guards: Protects system directories and critical paths from deletion
- Interactive Prompts: Clear warnings with risk levels and confirmation for dangerous operations
- Configurable Rules: Whitelist/blacklist commands, customize protection levels
- Multiple Modes: Interactive, strict (block all), or warn-only mode
Installation
npm install -g ai-code-guardrails
Or use with npx:
npx ai-code-guardrails check "rm -rf /"
Quick Start
Check a Command
Analyze a command without executing it:
guardrails check "rm -rf /tmp/test"
guardrails check "git push --force origin main"
guardrails check "DROP TABLE users"
Run with Protection
Execute a command with safety checks:
guardrails run "rm -rf ./node_modules"
guardrails run "git reset --hard HEAD~3"
Interactive Shell Mode
Start a protected shell session:
guardrails wrap
guardrails> rm -rf /
Usage
Commands
guardrails check <command> | Analyze a command without executing |
guardrails run <command> | Analyze and execute with confirmation |
guardrails wrap | Start interactive protected shell |
guardrails init | Create a config file |
guardrails whitelist add <cmd> | Add command to whitelist |
guardrails blacklist add <cmd> | Add command to blacklist |
Options
guardrails check --json "command"
guardrails run --mode strict "cmd"
guardrails run --mode warn "cmd"
guardrails run --yes "cmd"
guardrails run -c ./config.yml "cmd"
Modes
interactive | Prompt for confirmation on dangerous commands (default) |
strict | Block all dangerous commands without prompting |
warn | Show warnings but allow execution |
Configuration
Create a .guardrails.yml file in your project or home directory:
guardrails init
Example Configuration
enabled: true
mode: interactive
whitelist:
commands:
- git status
- git log
- npm install
paths: []
patterns: []
blacklist:
commands: []
paths: []
patterns: []
rules:
shell:
enabled: true
blockRmRf: true
blockChmod777: true
blockDd: true
blockMkfsFormat: true
git:
enabled: true
blockForcePush: true
blockHardReset: true
blockMainBranchPush: true
protectedBranches:
- main
- master
- production
sql:
enabled: true
blockDrop: true
blockDelete: true
blockTruncate: true
requireWhereClause: true
filesystem:
enabled: true
protectedPaths:
- /
- /etc
- /usr
blockRecursiveDelete: true
blockSystemDirs: true
What It Protects Against
Shell Commands
rm -rf / - Root directory deletion
rm -rf * - Wildcard deletion
chmod 777 - World-writable permissions
dd of=/dev/sda - Direct disk writes
mkfs.ext4 /dev/sda - Disk formatting
curl | sh - Piped execution from remote
- Fork bombs
Git Operations
git push --force - Force pushes
git reset --hard - Hard resets
git clean -fdx - Aggressive cleaning
- Push to main/master/production branches
- Deleting protected branches
SQL Statements
DROP TABLE / DROP DATABASE
DELETE FROM without WHERE
TRUNCATE TABLE
UPDATE without WHERE
- Operations on production databases
Filesystem Operations
- Deleting system directories (
/, /etc, /usr, etc.)
- Deleting home directory
- Overwriting system config files
- Dangerous permission changes
Programmatic Usage
import { analyzeCommand, CommandAnalyzer } from 'ai-code-guardrails';
const result = analyzeCommand('rm -rf /');
console.log(result.safe);
console.log(result.riskLevel);
console.log(result.issues);
const analyzer = new CommandAnalyzer({
rules: {
git: {
protectedBranches: ['main', 'develop']
}
}
});
const analysis = analyzer.analyze('git push --force origin main');
Integration with AI Tools
Cursor
Add to your Cursor settings:
{
"terminal.integrated.shellIntegration.enabled": true,
"terminal.integrated.profiles.linux": {
"guardrails": {
"path": "guardrails",
"args": ["wrap"]
}
}
}
Git Hooks
Add a pre-commit hook to check SQL migrations:
#!/bin/bash
for file in $(git diff --cached --name-only | grep '\.sql$'); do
guardrails check "$(cat $file)" || exit 1
done
CI/CD Pipeline
See the GitHub Action in .github/workflows/guardrails.yml for CI integration.
Risk Levels
low | Green | Safe to execute |
medium | Yellow | Proceed with caution |
high | Red | Potentially dangerous |
critical | Red BG | Extremely dangerous - requires explicit confirmation |
Exit Codes
| 0 | Command is safe / executed successfully |
| 1 | Command blocked or has risks |
Contributing
Issues and PRs welcome! Please check existing issues before submitting.
License
MIT