Skip to main content

Ultra-lightweight, zero-dependency security guardrail and loop-detection engine for AI Agent Workflows.

Project description

🛡️ ZeroGuard: The Ultra-Lightweight AI Security Sentry

ZeroGuard ZeroGuard ZeroGuard ZeroGuard

ZeroGuard is a production-grade, zero-dependency security engine designed to protect autonomous AI Agent workflows from infinite logic loops and malicious code execution. Built entirely with the Python Standard Library, it provides sub-millisecond protection without the latency overhead of containerization.


🚀 Key Features

1. 🔄 Deterministic Loop Detection (LoopGuard)

Prevents AI agents from falling into recursive logic traps that exhaust API credits.

  • Mechanics: Thread-safe execution history with cryptographic state-hashing.
  • Fingerprinting: SHA-256 signatures of tool calls with lexicographically sorted arguments.
  • Circuit Breaker: Automatic hard-stop after 3 identical repetitions.

2. ⚡ Sub-Millisecond AST Pre-Screening (ExecutionGuard)

Secures "CodeMode" agent execution without the 200ms+ latency of Docker sandboxing.

  • Deny-by-Default: Strict allowlist of safe Python AST nodes.
  • Capability Trapping: Blocks import, os, subprocess, eval, exec, and private dunder attribute exploration.
  • Isolated Namespace: Executes code in a restricted scope with zero access to the host environment.

3. 📜 Enterprise Compliance (AuditLogger)

Full traceability for regulatory requirements like the EU AI Act (Article 12).

  • High-Density Metrics: Newline-delimited JSON event trails.
  • ISO 8601 UTC: Cryptographically verifiable timestamps.
  • Status Indicators: ALLOWED, HARD_BLOCK, and EXECUTION_TERMINATED states.

🛠️ Installation

ZeroGuard requires Zero External Dependencies. Just drop the zeroguard directory into your project.

pip install . # or simply copy the folder

💻 Quick Start

Protect your Tools from Loops

from zeroguard import ZeroGuardEngine

engine = ZeroGuardEngine(loop_threshold=3)

@engine.breaker()
def get_weather(location: str):
    # This tool is now protected from infinite agent loops
    return f"Weather in {location} is 72°F"

Secure Dynamic Code Execution

code = "import os; os.system('rm -rf /')" # Malicious attempt

try:
    engine.guard_code_execution(code)
except ZeroGuardSecurityError as e:
    print(f"Attack Blocked: {e}")

🏗️ Architecture

ZeroGuard
├── engine.py          # Unified Interceptor Interface
├── loop_detector.py   # SHA-256 State Fingerprinting
├── security.py        # AST Node Visitor & Sandbox
├── compliance.py      # ISO 8601 JSON Audit Stream
└── exceptions.py      # Fail-Closed Error Tree

🛡️ Security Posture: Fail-Closed

ZeroGuard is designed with a Hard Block philosophy. If any internal component encounters an error or a policy violation, the engine defaults to a HARD_BLOCK, ensuring that your application remains secure even under unexpected conditions.


📈 Performance

Action Latency Overhead
AST Validation < 0.5ms Negligible
Loop Fingerprinting < 0.2ms Negligible
Audit Logging < 0.1ms Async-compatible

📄 License

MIT License. Built for the open-source AI community.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zeroguard_policy-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zeroguard_policy-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file zeroguard_policy-0.1.0.tar.gz.

File metadata

  • Download URL: zeroguard_policy-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for zeroguard_policy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6d0b71387fcf91e3ff6d7dd2f6312116317e148e9ccb406d8940460b46669081
MD5 53ce9cc15cf54ef4b26d4fbf7b9e44a5
BLAKE2b-256 8a1518febacfd590a34dadfb2f5b846ce1a692a9ae55f5ba88dd94571449a552

See more details on using hashes here.

File details

Details for the file zeroguard_policy-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for zeroguard_policy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8d1a955dbeaad361f141ac74e2913ac5f58b280179fbb028a21abc368fbbda5
MD5 bd7687f1efe7d3c1651e4d327827e9b4
BLAKE2b-256 06f2519ebc4a6cd22864badc1ff3049a407670b4dadfabcda678ac3dfd433774

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page