Runtime security guardrails for AI agents — inspect, control, and audit every tool call. Zero-dependency local mode included.
Project description
AgentShield Python SDK
Lightweight security guardrails for AI agents. All security logic runs server-side.
Quick Start
from agentshield import Shield
shield = Shield() # reads AGENTSHIELD_API_KEY from env
@shield.guard
async def send_email(to: str, body: str) -> str:
... # your tool implementation
# The server decides: ALLOW, BLOCK, or REQUIRE_CONFIRMATION
await send_email(to="user@company.com", body="Hello")
Session Mode
async with shield.session("Summarize my emails") as s:
result = await s.guarded_executor.execute(
"read_inbox", {"limit": 10}, read_inbox_fn
)
Error Handling
from agentshield import Shield, ToolCallBlocked, ConfirmationRejected, ServerError
shield = Shield()
@shield.guard
async def send_email(to: str, body: str) -> str:
...
try:
await send_email(to="user@test.com", body="hi")
except ToolCallBlocked as e:
print(f"Blocked: {e.reason} (trace: {e.trace_id})")
except ConfirmationRejected:
print("User declined confirmation")
except ServerError as e:
print(f"Server error: {e}")
Configuration
# Explicit configuration
shield = Shield(
api_key="your-key",
base_url="https://shield.yourcompany.com",
timeout=10.0,
max_retries=3,
agent_id="my-agent",
)
Or via environment variables:
AGENTSHIELD_API_KEY(required)AGENTSHIELD_BASE_URL(default: http://localhost:8000)AGENTSHIELD_TIMEOUT(default: 10.0)AGENTSHIELD_AGENT_ID
Or via agentshield.yaml in the working directory.
Data Sanitization
# Sanitize external data before processing
result = await shield.sanitize(
data=email_body,
source="email/external",
)
# result.content has hidden injections removed
# result.trust_level shows the computed trust level
Framework Integrations
from agentshield.integrations import LangChainShield, CrewAIShield
# LangChain
guarded = LangChainShield(shield).wrap(agent_executor)
# CrewAI
guarded = CrewAIShield(shield).wrap(crew)
# AutoGen
from agentshield.integrations import AutoGenShield
AutoGenShield(shield).wrap(assistant)
# Claude Agent SDK
from agentshield.integrations import ClaudeAgentShield
guarded_handler = ClaudeAgentShield(shield).wrap(my_tool_handler)
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
agentshield_runtime-0.1.0.tar.gz
(19.4 kB
view details)
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 agentshield_runtime-0.1.0.tar.gz.
File metadata
- Download URL: agentshield_runtime-0.1.0.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f7f4cf275859995d95b47d7cef2f6c76aaad20d229b8db6c7b09ed4dd797d24
|
|
| MD5 |
c0f16dc7744e01fabdce4bbf88227927
|
|
| BLAKE2b-256 |
134e40d84ef21d3f41cea239c92f2443762230b0a2b6ec4977b33906cc08313c
|
File details
Details for the file agentshield_runtime-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentshield_runtime-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0dd0a0efa7b16f2d3e629905070095461d23bd5ade67bb3f2402cc7fd03e8f5
|
|
| MD5 |
bf23de2bbc4e486cc412e7d138e6b7c3
|
|
| BLAKE2b-256 |
3ddae884fd30b7130ab44f94e40556a900a68d323782fa503815da184df697a9
|