New:Socket for Asana Is Now Available.Learn more
Get Started

ai-code-guardrails

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-code-guardrails

CLI wrapper for AI coding assistants that prevents destructive operations. Intercepts dangerous commands before execution.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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
# All commands will be analyzed before execution
guardrails> rm -rf /
# [CRITICAL] Recursive deletion from root directory
# Do you want to execute this dangerous command? (y/N)

Usage

Commands

CommandDescription
guardrails check <command>Analyze a command without executing
guardrails run <command>Analyze and execute with confirmation
guardrails wrapStart interactive protected shell
guardrails initCreate a config file
guardrails whitelist add <cmd>Add command to whitelist
guardrails blacklist add <cmd>Add command to blacklist

Options

guardrails check --json "command"     # Output as JSON
guardrails run --mode strict "cmd"    # Strict mode (block dangerous)
guardrails run --mode warn "cmd"      # Warn mode (show warnings only)
guardrails run --yes "cmd"            # Skip confirmation (dangerous!)
guardrails run -c ./config.yml "cmd"  # Use custom config

Modes

ModeBehavior
interactivePrompt for confirmation on dangerous commands (default)
strictBlock all dangerous commands without prompting
warnShow 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';

// Quick analysis
const result = analyzeCommand('rm -rf /');
console.log(result.safe);        // false
console.log(result.riskLevel);   // 'critical'
console.log(result.issues);      // Array of detected issues

// With custom config
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
# .git/hooks/pre-commit
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

LevelColorMeaning
lowGreenSafe to execute
mediumYellowProceed with caution
highRedPotentially dangerous
criticalRed BGExtremely dangerous - requires explicit confirmation

Exit Codes

CodeMeaning
0Command is safe / executed successfully
1Command blocked or has risks

Contributing

Issues and PRs welcome! Please check existing issues before submitting.

License

MIT

Keywords

ai

FAQs

Package last updated on 27 Dec 2025

Related posts