Deterministic execution-level safety layer between AI agents and real systems (shell, files, SQL, HTTP).
Project description
AI Execution Firewall
A control layer that intercepts AI-generated actions (shell commands, file ops, SQL queries, HTTP requests) and gates them through a deterministic policy pipeline before they execute.
AI → Action → Firewall → Decision → Execution
Install
pip install ai-execution-firewall
For development (editable install with test deps):
git clone https://github.com/Shahriyar-Khan27/ai_firewall.git
cd ai_firewall
pip install -e ".[dev]"
Quickstart
CLI
guard eval "rm -rf /" # → BLOCK (no execution)
guard run "echo hello" # → ALLOW, executes
guard run "rm ./tmp.txt" # → REQUIRE_APPROVAL, prompts y/N
guard policy show # print effective ruleset
Python SDK
from ai_firewall import Guard, Action
guard = Guard()
result = guard.execute(Action.shell("echo hello"))
print(result.decision.decision, result.execution.exit_code)
Shell hook
source scripts/guard-shell-hook.sh # wraps rm, mv, dd, chmod, chown
VS Code extension
In-editor approval UI replacing the terminal prompt with a webview that shows risk, findings, git context, and the unified diff. See vscode-extension/README.md for build + F5 instructions.
cd vscode-extension && npm install && npm run compile
# then open the folder in VS Code and press F5
Pipeline
Every guard.execute(action) call runs:
- Intent classifier — regex on payload →
FILE_DELETE | FILE_WRITE | SHELL_EXEC | CODE_MODIFY | … - Risk analyzer — table lookup on intent + feature flags →
LOW | MEDIUM | HIGH | CRITICAL - Policy engine — YAML rules →
ALLOW | BLOCK | REQUIRE_APPROVAL - Impact engine — dry-run glob expansion, file stat, unified diff, AST findings (removed funcs/tests, auth identifiers), git context (uncommitted, untracked, gitignored)
- Risk bump — impact findings can raise risk and re-trigger policy (e.g. removing a function bumps to HIGH)
- Decision engine — combines verdict + risk + impact
BLOCK raises immediately. REQUIRE_APPROVAL invokes the approval function (default: interactive CLI prompt). ALLOW runs through the matching adapter (shell or file).
Every evaluated action is appended to logs/audit.jsonl.
Custom rules
Pass --rules path/to/rules.yaml (CLI) or Guard(rules_path=...) (SDK). See ai_firewall/config/default_rules.yaml for the schema:
shell_exec:
blocked:
- 'rm\s+-rf\s+/'
require_approval:
risk_at_or_above: HIGH
file_delete:
require_approval: true
Scope
Phase 1 (shipped): shell + filesystem, rule-based classifier, CLI prompt approval, CLI / SDK / shell-hook surfaces.
Phase 2 (shipped): unified diff for code edits, AST-aware risk findings, git-aware impact, VS Code extension with webview approval UI.
Out / future: DB / API adapters, ML classifiers, cloud control plane, web dashboard, sandboxed shell dry-run.
Tests
pytest -q
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_execution_firewall-0.1.0.tar.gz.
File metadata
- Download URL: ai_execution_firewall-0.1.0.tar.gz
- Upload date:
- Size: 40.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17329a2acb5a51b6c0e2ad95264be4a3c5ec6d5f873453e147897286a6cb3d79
|
|
| MD5 |
4396f6dcc0f506e1f0fbe6733f26e178
|
|
| BLAKE2b-256 |
5995b48b90a331ed7ad07eca896ee9f1a38b00a29359adec98b53d4a947187a5
|
File details
Details for the file ai_execution_firewall-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_execution_firewall-0.1.0-py3-none-any.whl
- Upload date:
- Size: 38.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33c4350621ba0e9df8a8e349daa1760b15dc0ebaf18733ad53038c8d9dccaafe
|
|
| MD5 |
d1d244fe43cc50c7ae7e9387989efa76
|
|
| BLAKE2b-256 |
56cfdf36b54e660f71181d58c4537f7487932a6e6dfcbb4a09a8b8f9d14d11b1
|