npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-code-guardrails

v1.0.0

Published

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

Readme

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

| Command | Description | |---------|-------------| | 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"     # 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

| Mode | Behavior | |------|----------| | 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';

// 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

| Level | Color | Meaning | |-------|-------|---------| | low | Green | Safe to execute | | medium | Yellow | Proceed with caution | | high | Red | Potentially dangerous | | critical | Red BG | Extremely dangerous - requires explicit confirmation |

Exit Codes

| Code | Meaning | |------|---------| | 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