Skip to main content

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)

Release files for agentshield-runtime 0.1.0

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-runtime 0.1.0
File Size Uploaded
agentshield_runtime-0.1.0.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentshield-runtime 0.1.0
File Interpreter ABI Platform
agentshield_runtime-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.7 kB

Release files / agentshield_runtime-0.1.0.tar.gz

Download URL agentshield_runtime-0.1.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2f7f4cf275859995d95b47d7cef2f6c76aaad20d229b8db6c7b09ed4dd797d24
BLAKE2b-256 checksum
How to use checksums
134e40d84ef21d3f41cea239c92f2443762230b0a2b6ec4977b33906cc08313c
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / agentshield_runtime-0.1.0-py3-none-any.whl

Download URL agentshield_runtime-0.1.0-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0dd0a0efa7b16f2d3e629905070095461d23bd5ade67bb3f2402cc7fd03e8f5
BLAKE2b-256 checksum
How to use checksums
3ddae884fd30b7130ab44f94e40556a900a68d323782fa503815da184df697a9
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.1.0 This release

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