Skip to main content

ShadowAudit

Deprecated: ShadowAudit has been renamed to CapFence. New projects should install capfence and use the maintained repository: https://github.com/capfencelabs/capfence

Deterministic runtime authorization for AI agent tool calls.

PyPI version Python versions License: MIT Tests: passing

ShadowAudit sits between AI agents and their tools. It evaluates every tool call against deterministic policy before execution, then allows it, blocks it, or requires approval.

It is closer to IAM, Open Policy Agent, API gateways, and admission controllers than prompt guardrails or moderation.

Agent -> ShadowAudit -> Tool
          |
          +-- allow
          +-- deny
          +-- require approval

Why This Exists

Agents increasingly call tools that can move money, edit databases, run shell commands, read files, modify permissions, and operate SaaS admin APIs.

Prompt instructions are not an execution boundary. ShadowAudit gives those tool calls an explicit runtime authorization layer:

  • No LLM call in the gate path.
  • Policy-as-code decisions.
  • Default-deny behavior when policy does not match.
  • Fail-closed handling for policy and audit failures.
  • Local audit logs with hash-chain verification.
  • Observe mode for safe rollout before enforcement.

Install

pip install capfence

This shadowaudit package remains available only as a deprecated compatibility release for existing users. It will emit a warning at import time.

60-Second Example

Create a policy:

deny:
  - capability: shell.execute
    contains: "rm -rf"

require_approval:
  - capability: payments.transfer
    amount_gt: 1000

allow:
  - capability: shell.execute
  - capability: payments.transfer
    amount_lte: 1000

Evaluate a tool call before execution:

from shadowaudit.core.gate import Gate

gate = Gate()

result = gate.evaluate(
    agent_id="ops-agent",
    task_context="shell",
    risk_category="shell_execution",
    capability="shell.execute",
    policy_path="policies/shell_agent.yaml",
    payload={"command": "rm -rf /var/lib/postgresql"},
)

if not result.passed:
    raise PermissionError(f"Blocked: {result.reason}")

The dangerous command never reaches the tool.

Framework Integrations

ShadowAudit can wrap tools in:

  • LangChain
  • LangGraph
  • CrewAI
  • OpenAI Agents SDK
  • MCP
  • PydanticAI
  • LlamaIndex
  • AutoGen
  • Direct Python runtimes

LangChain example:

from shadowaudit import ShadowAuditTool
from langchain.tools import ShellTool

safe_shell = ShadowAuditTool(
    tool=ShellTool(),
    agent_id="ops-agent",
    capability="shell.execute",
    policy_path="policies/shell_agent.yaml",
)

CLI Workflows

Scan for ungated tools:

shadowaudit check ./src --fail-on-ungated

Validate a policy:

shadowaudit check-policy policies/shell_agent.yaml

Replay a trace through policy:

shadowaudit simulate --trace-file traces/agent_trace.jsonl --compare

Verify audit-log integrity:

shadowaudit verify --audit-log audit.db

Rollout Path

  1. Start in observe mode and log decisions without blocking.
  2. Review audit logs and tune policies.
  3. Enforce policy for high-risk tools.
  4. Add CI checks so new ungated tools cannot quietly ship.
  5. Replay incidents and policy changes against saved traces.

What ShadowAudit Is Not

ShadowAudit is a runtime authorization and audit layer. It does not replace:

  • sandboxing for shell/code execution
  • least-privilege credentials
  • network egress controls
  • prompt-injection defenses
  • human review for genuinely ambiguous high-risk actions

Use it as the deterministic control point before tool execution.

Why Not Prompt Guardrails?

Prompt guardrails are useful, but they do not enforce execution. A prompt can be bypassed, misinterpreted, or ignored under pressure. ShadowAudit adds a deterministic enforcement boundary that blocks tool calls before they execute and records a tamper-evident audit trail.

Where It Sits In Your Stack

Agent framework -> ShadowAudit gate -> Tool/API/DB/Shell

ShadowAudit does not replace sandboxing, network egress controls, or least-privilege credentials. It complements them by enforcing runtime policy at the tool boundary.

Project Status

ShadowAudit is beta infrastructure for agent tool governance. The repo includes:

  • deterministic gate and policy engine
  • local audit log with hash-chain verification
  • approval workflows
  • observe mode and bypass audit trails
  • framework adapters
  • MCP gateway and adapter
  • static scanner and CI mode
  • OWASP Agentic Top 10 and EU AI Act evidence reports
  • typed Python package with ruff, mypy, and pytest coverage

Current local verification: run pytest -q.

Documentation

Useful starting points:

Contributing

git clone https://github.com/capfencelabs/capfence.git
cd capfence
pip install -e ".[dev]"
pytest tests/ -q

Policy recipes, framework adapters, taxonomies, docs, and focused bug reports are welcome.

License

MIT License

Built by CapFence Labs

Release files for shadowaudit 0.6.3

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

Source distribution (sdist)

Source distribution for shadowaudit 0.6.3
File Size Uploaded
shadowaudit-0.6.3.tar.gz 165.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shadowaudit 0.6.3
File Interpreter ABI Platform
shadowaudit-0.6.3-py3-none-any.whl Python 3 none any Details

Total release size: 278.0 kB

Release files / shadowaudit-0.6.3.tar.gz

Download URL shadowaudit-0.6.3.tar.gz
Size 165.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b1c3d89f1ab21354015ac8030e4ee22dc170ba91b2ba14c0ede55c30d5d09474
BLAKE2b-256 checksum
How to use checksums
b5674018471059b966b6ec99bfc4e56336a42c79961963748f7ce888eed03fac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / shadowaudit-0.6.3-py3-none-any.whl

Download URL shadowaudit-0.6.3-py3-none-any.whl
Size 112.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79d6e9215e47ab340f1dd23e89be62f14eb988e22c7bb5442d210f041829a60f
BLAKE2b-256 checksum
How to use checksums
234ca22d82b270965aac934146793c3eaa5410393ee70accf7f44ef5cbaf85b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

0.6.3 This release

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

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