Skip to main content

AgentShield

AgentShield is a lightweight Python SDK (v0.1.5) 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.

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.

Release files for agentshield-api 0.1.5

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

Source distribution (sdist)

Source distribution for agentshield-api 0.1.5
File Size Uploaded
agentshield_api-0.1.5.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentshield-api 0.1.5
File Interpreter ABI Platform
agentshield_api-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / agentshield_api-0.1.5.tar.gz

Download URL agentshield_api-0.1.5.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d885339814ab71efdd674911a91a197fa2b90b5499d46c656ca630543b144c55
BLAKE2b-256 checksum
How to use checksums
7370e6a514c42d38d2a44b2829c17fcba04ad548c1ea4c03f6e5dce6ae8ed862
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / agentshield_api-0.1.5-py3-none-any.whl

Download URL agentshield_api-0.1.5-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c5fbc26da7ef6bbd50fed26e4433d9f22e729f669cfbf66bceadb53113554a8
BLAKE2b-256 checksum
How to use checksums
082d6ef213d3d0b28e546961b8b4ceb6c687cf852d5e00bd40a788e37058fd73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

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