Skip to main content

Agent-Safeguard

A lightweight, enterprise-grade runtime sandboxing and definition-time guardrail framework for Python applications, built to safely run code generated or modified by AI agents.

📖 Full Documentation: shield-docs-mu.vercel.app


Why Agent-Safeguard?

AI coding agents are excellent at generating code but often lack a global understanding of architectural boundaries, leading to path traversal bypasses, illegal imports, API resource leaks, or infinite lockups.

Agent-Safeguard captures these boundary violations, blocks them in real-time, and generates structured JSON diagnostic reports (shield_reports/violation_report.json) that AI agents can ingest to automatically self-correct and rewrite their code!

Core Protection Areas

  • Architectural Integrity (AST): @shield, @freeze, and @lock_signature to scan imports, prevent code mutations, and secure API parameters.
  • Security & Resource Sandboxing: @restrict_network, @restrict_fs, @virtual_fs (redirecting all writes to RAM), database locks, and memory/timeout limits.
  • AI & Prompt Guidelines: @prompt_inject (docstring constraints) and @prompt_assert (Gemini-powered semantic assertions).
  • Central Policy Injection: Define rules globally in a central shield.yaml to prevent agents from simply deleting Python decorators from source files.

Installation

pip install agent-safeguard

Import it in your Python code using the underscore name agent_shield:

from agent_shield import shield, virtual_fs, restrict_db

Quick Start Example

  1. Create a shield.yaml rule file in your project root:
rules:
  - pattern: "sandbox_code.*"
    timeout: 0.5
    virtual_fs: true
    restrict_network: ["api.stripe.com"]
  1. Run your functions normally; Agent-Safeguard will automatically enforce limits and write JSON reports on violation:
# sandbox_code.py
import urllib.request

def process_data():
    # Attempting to fetch unauthorized API will block and generate a violation report
    response = urllib.request.urlopen("https://unauthorized-api.com")
    return response.read()

License

This project is licensed under the Apache License 2.0. See LICENSE for details.

Metadata

Release files for agent-safeguard 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-safeguard 1.0.6
File Size Uploaded Provenance
agent_safeguard-1.0.6.tar.gz 42.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-safeguard 1.0.6
File Interpreter ABI Platform
agent_safeguard-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 87.3 kB

Release files / agent_safeguard-1.0.6.tar.gz

Download URL agent_safeguard-1.0.6.tar.gz
Size 42.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d5d15a69c55df3f920cc792f46907aedd5e765cba91baac8908ac475ad3032ab
BLAKE2b-256 checksum
How to use checksums
eb4226f7b8161b721ef28333539081eb87f17f932cfec7e3e47c84904f75fce6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / agent_safeguard-1.0.6-py3-none-any.whl

Download URL agent_safeguard-1.0.6-py3-none-any.whl
Size 44.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e992cde7bb36b7843691b1aefbaad31d39a6f55e26880f416507bd87020e88cd
BLAKE2b-256 checksum
How to use checksums
821a4f35186b590dc2d8e00fddd194f05f160d1368ee4b0a9a5a9dabe2ca98a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for agent-safeguard 1.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page