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 edits, SQL queries, HTTP requests — and gates them through a deterministic policy pipeline before they execute.
AI → Action → Firewall → Decision → Execution
The firewall classifies intent, scores risk, applies YAML rules, simulates impact (unified diff for code, AST findings, git context, SSRF / leaked-secret detection for URLs), and returns one of ALLOW / BLOCK / REQUIRE_APPROVAL. Every decision is appended to an audit log.
Install
Python package (PyPI):
pip install ai-execution-firewall
VS Code extension (Marketplace):
VS Code → Extensions panel → search "AI Execution Firewall" → Install
Or from the command line:
code --install-extension sk-dev-ai.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
# Shell
guard eval "rm -rf /" # → BLOCK (no execution)
guard run "echo hello" # → ALLOW, executes
guard run "rm ./tmp.txt" # → REQUIRE_APPROVAL, prompts y/N
# SQL (analyze-only by default — never touches your DB)
guard sql "SELECT * FROM users" # → ALLOW · LOW
guard sql "DELETE FROM users" # → REQUIRE_APPROVAL · CRITICAL (no WHERE)
guard sql "DROP DATABASE prod" # → BLOCK
# Opt-in execute mode against a real SQLite DB:
guard sql "DELETE FROM users WHERE id=1" --execute --connection ./app.sqlite
# HTTP (analyze-only by default — never makes the request)
guard api GET https://api.example.com/users # → ALLOW
guard api GET http://169.254.169.254/ # → CRITICAL (cloud metadata SSRF)
guard api POST https://api.example.com/log --body '{"k":"AKIAIOSFODNN7EXAMPLE"}'
# → CRITICAL (AWS key in body)
# Opt-in execute mode (issues request via stdlib urllib):
guard api POST https://api.example.com/things --body '{"x":1}' --execute
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)
Action.file(...), Action.db(...), Action.api(...) cover the other three action types.
Shell hook
source scripts/guard-shell-hook.sh # wraps rm, mv, dd, chmod, chown
VS Code extension
After installing from the Marketplace, the Command Palette (Ctrl+Shift+P) gives you six commands under AI Firewall:
- Run Shell Command… / Evaluate Selected Text as Shell Command
- Evaluate SQL Query… / Evaluate Selected Text as SQL
- Evaluate HTTP Request…
- Show Effective Policy
Risky actions open a themed approval webview with the risk badge, intent / decision pills, findings list, git context, and a syntax-coloured unified diff (for code edits). One click to Approve & run, one click to Reject — both record an audit row. See vscode-extension/README.md for build / debug / packaging instructions.
Pipeline
Every guard.execute(action) call runs:
- Intent classifier — regex / SQL parse / URL parse → one of
FILE_DELETE | FILE_WRITE | FILE_READ | SHELL_EXEC | CODE_MODIFY | DB_READ | DB_WRITE | DB_DESTRUCTIVE | API_READ | API_WRITE | API_DESTRUCTIVE - Risk analyzer — table lookup on intent + feature flags →
LOW | MEDIUM | HIGH | CRITICAL - Policy engine — YAML rules →
ALLOW | BLOCK | REQUIRE_APPROVAL(first pass) - Impact engine — best-effort dry-run:
- Files: glob expansion, file stat, unified diff, AST findings (removed funcs / tests, auth identifiers), git context (uncommitted, untracked, gitignored)
- SQL:
sqlglotAST → DELETE/UPDATE without WHERE, DROP DATABASE/SCHEMA/TABLE, TRUNCATE, GRANT/REVOKE, multiple statements - HTTP: cloud metadata endpoints, private/loopback hosts (SSRF), URL credentials, secrets in query string, non-HTTP schemes, destructive paths; body + Authorization-header secret scanning (AWS / GitHub / Slack / Stripe / Google / Anthropic / OpenAI / PEM keys / JWTs)
- Risk bump — impact findings can raise risk and re-trigger policy (e.g. removing a function bumps to HIGH; metadata host bumps to CRITICAL)
- Decision engine — combines verdict + risk + impact
BLOCK raises immediately. REQUIRE_APPROVAL invokes the approval function (default: interactive CLI prompt; in VS Code: webview button). ALLOW runs through the matching adapter.
Every evaluated action is appended to logs/audit.jsonl.
Adapters
| Action type | Default adapter | Opt-in execute adapter |
|---|---|---|
shell |
ShellAdapter (subprocess) |
— (always executes) |
file |
FileAdapter (pathlib) |
— (always executes) |
db |
DBAnalyzeAdapter — never opens a DB |
SQLiteExecuteAdapter via --execute --connection <sqlite-path> |
api |
APIAnalyzeAdapter — never sends a request |
HTTPExecuteAdapter via --execute (stdlib urllib) |
DB and API default to analyze-only so the firewall never touches your database or network unless you explicitly opt in.
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
db_destructive:
blocked:
- 'DROP\s+DATABASE'
require_approval: true
api_destructive:
require_approval: true
Scope
Shipped (v0.1.0):
- Phase 1: shell + filesystem, rule-based classifier, CLI prompt approval, CLI / SDK / shell-hook surfaces.
- Phase 2: unified diff for code edits, AST-aware risk findings, git-aware impact, VS Code extension with webview approval UI.
- Phase 3: SQL gating via
sqlglot, HTTP gating via stdliburllib, secret-scanning of request bodies and Authorization-style headers, opt-in execute adapters for SQLite and HTTP.
Out / future:
- Postgres / MySQL execute adapters (currently SQLite only)
- Sandboxed shell dry-run
- Cloud control plane / web dashboard
- Team policy distribution
Tests
pytest -q
159 tests across all phases. CI runs on Python 3.11 / 3.12 / 3.13 on every push.
Release flow
Pushing a tag matching v* automatically:
- runs the full test matrix on GitHub Actions,
- builds sdist + wheel,
- publishes to PyPI via Trusted Publishing (no API token in CI).
# Bump version in pyproject.toml + add CHANGELOG entry, commit, then:
git tag -a v0.1.1 -m "v0.1.1"
git push --tags
# PyPI is updated within ~60 seconds.
VS Code Marketplace publishing is currently manual — re-build the .vsix (npx vsce package --no-yarn from vscode-extension/) and upload via the Marketplace publisher manage page.
Links
- PyPI: https://pypi.org/project/ai-execution-firewall/
- VS Code Marketplace: https://marketplace.visualstudio.com/items?itemName=sk-dev-ai.ai-execution-firewall
- GitHub releases: https://github.com/Shahriyar-Khan27/ai_firewall/releases
- CHANGELOG: CHANGELOG.md
License
MIT — see LICENSE.
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.1.tar.gz.
File metadata
- Download URL: ai_execution_firewall-0.1.1.tar.gz
- Upload date:
- Size: 41.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c68d17604b8cc2c20762d14cab92b3ff965244f5f5401971909527fc0f24326
|
|
| MD5 |
0e2e2e7a2fa24b4df143c1295dc53a3b
|
|
| BLAKE2b-256 |
251431cdc04255075ac232cbcfea49bc52d7b491650a99f183f639f33e5bcdce
|
Provenance
The following attestation bundles were made for ai_execution_firewall-0.1.1.tar.gz:
Publisher:
publish.yml on Shahriyar-Khan27/ai_firewall
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_execution_firewall-0.1.1.tar.gz -
Subject digest:
1c68d17604b8cc2c20762d14cab92b3ff965244f5f5401971909527fc0f24326 - Sigstore transparency entry: 1412025878
- Sigstore integration time:
-
Permalink:
Shahriyar-Khan27/ai_firewall@343142757413eaf2ff23aa4c80edafb2c8d02db3 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Shahriyar-Khan27
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@343142757413eaf2ff23aa4c80edafb2c8d02db3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ai_execution_firewall-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ai_execution_firewall-0.1.1-py3-none-any.whl
- Upload date:
- Size: 40.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4651d1cb7b4d6cf5634e3c36acb40216fb6c7c6d4f1dbde1048132b1df906fef
|
|
| MD5 |
96f7390d2635f66ae315dc26a8fcf6ab
|
|
| BLAKE2b-256 |
95a8e821ad0d64e428ec8418e0e1cef254643ef02c38c899f126949a0abed9f8
|
Provenance
The following attestation bundles were made for ai_execution_firewall-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Shahriyar-Khan27/ai_firewall
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_execution_firewall-0.1.1-py3-none-any.whl -
Subject digest:
4651d1cb7b4d6cf5634e3c36acb40216fb6c7c6d4f1dbde1048132b1df906fef - Sigstore transparency entry: 1412025964
- Sigstore integration time:
-
Permalink:
Shahriyar-Khan27/ai_firewall@343142757413eaf2ff23aa4c80edafb2c8d02db3 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Shahriyar-Khan27
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@343142757413eaf2ff23aa4c80edafb2c8d02db3 -
Trigger Event:
push
-
Statement type: