Skip to main content

Secure middleware SDK for AI agents.

Project description

AgentShield

AgentShield is a lightweight Python SDK (v0.1.1) that provides a secure middleware layer between AI agents and developer resources such as repositories, file systems, APIs, and tools.

Its purpose is to prevent accidental leakage of sensitive data (API keys, passwords, tokens, etc.) while still allowing agents to perform useful work.

Features

  • SecureFS – safe file reader that scans and redacts secrets.
  • SecretScanner – regex/entropy-based detection engine.
  • Redactor – replaces detected secrets with placeholders.
  • OutputGuard – inspects agent outputs and blocks or redacts leaks.
  • Policy – YAML-driven configuration for allowed/blocked types.

Getting Started

Install via pip (when released) or add the package to your project.

pip install agentshield-api

If you’re just trying the library out against a test index, you can install from TestPyPI with:

pip install -i https://test.pypi.org/simple agentshield-api

Note that the distribution on PyPI is named agentshield-api (not agentshield) to avoid collisions with other projects.

from agentshield import SecureFS, OutputGuard

fs = SecureFS()
safe_content = fs.read_file("config.env")

guard = OutputGuard()
clean_output = guard.inspect("some text containing secret=abc123")

Running the test suite

A small pytest-based test suite lives under tests/. After installing requirements (PyYAML, pytest), run:

python -m pytest -q

You should see five tests covering core functionality.

Project Structure

Extending detection

The :class:agentshield.secret_scanner.SecretScanner class ships with a set of common regexes (API keys, tokens, AWS formats, JWTs, etc.). If you need to recognise additional secrets, simply:

from agentshield.secret_scanner import SecretScanner
import re

scanner = SecretScanner()
scanner.register_pattern("MY_SECRET", re.compile(r"mysecret=\S+"))

Patterns are applied in the order they are registered, and you can also provide a custom list during initialization.

Custom policy

By default the library loads a YAML file named default_policy.yaml from the policies/ directory in the package. You can override this behaviour by suppling your own Policy instance:

from agentshield import SecureFS, Policy

policy = Policy(allowed=["ENV_VAR"], blocked=["API_KEY"], block_mode="error")
fs = SecureFS(policy=policy)

Or create your own YAML file and load it:

p = Policy.load_from_file("/path/to/my_policy.yaml")
guard = OutputGuard(policy=p)

The configuration schema is simple:

allowed:
  - ENV_VAR
blocked:
  - API_KEY
block_mode: redact  # or error or warn

This makes it easy to adapt AgentShield to your project’s risk profile.

Project Structure

agentshield/
  __init__.py
  secure_fs.py
  secret_scanner.py
  redactor.py
  output_guard.py
  policy.py
policies/
  default_policy.yaml
examples/
  example_usage.py
tests/
  test_*.py
pyproject.toml
requirements.txt
README.md
LICENSE

License

This project is open source under the Apache license.

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

agentshield_api-0.1.3.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

agentshield_api-0.1.3-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file agentshield_api-0.1.3.tar.gz.

File metadata

  • Download URL: agentshield_api-0.1.3.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for agentshield_api-0.1.3.tar.gz
Algorithm Hash digest
SHA256 21484d41fb3a90f3bf39552e6842ac952f1c76f780600e5ee7a7b130bab13792
MD5 2d50cff11556500c896c277fdae67f7f
BLAKE2b-256 44566cfb6d052d912c900cd64eb2f86bf88fdad8c635f15069c90a8fb8c2f023

See more details on using hashes here.

File details

Details for the file agentshield_api-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for agentshield_api-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a0bbaff54c9caf4e3ec9a1724ee7581d7f9912f83a587625910ecca38b963501
MD5 2eb9eb468d2bfe8c3a3198ebcccac457
BLAKE2b-256 3368e67605a0dd6c16b0dbf996fc044f898d5717904c6aa3505161b29b9768cc

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