Skip to main content

Runtime governance for AI agents — deterministic fail-closed enforcement. Wraps any agent tool and blocks dangerous calls before execution. Zero LLM calls, zero cloud dependencies, works offline.

Project description

CapFence

Execution authorization infrastructure for autonomous systems.

AI agents are non-deterministic. Real-world execution must not be.


PyPI version Python versions License: MIT Tests: passing

CapFence sits between autonomous systems and privileged execution targets (APIs, databases, filesystems, and gateways). It evaluates agent actions against declarative, capability-based policies—allowing, blocking, or queuing actions for approval.

It operates as a policy enforcement layer and verifiable audit log, bringing the control of IAM and transaction gateways to autonomous agent runtimes.

Agent SDK ──> CapFence Runtime ──> Target System
                   │
                   ├── [Allow]    ──> Safe Execution
                   ├── [Deny]     ──> Blocked
                   └── [Approval] ──> Temporary / Expiring Grant

Why CapFence

When autonomous agents call tools that modify cloud infrastructure, query databases, or execute payments, prompts are not security boundaries. A prompt can be bypassed, manipulated, or drift under model updates.

CapFence introduces an independent enforcement boundary:

  • Decoupled Access Control: Policy logic is isolated from the LLM and evaluated locally using a fast capability engine.
  • Fail-Closed by Default: If policy validation or audit logging fails, the action is blocked.
  • Tamper-Evident Audit Trails: Every decision is committed to a hash-chained, verifiable audit trail to prevent retroactive log alterations.

10-Second Example

1. Define Capability Policies (policies/ops.yaml)

Establish strict, resource-action-scope access limits. Unmatched capabilities default to deny.

policy_name: Production Security Policy
version: 2.0.0

allow:
  - filesystem.read.workspace

require_approval:
  - payment.transfer.*
  - deployment.execute.production

deny:
  - filesystem.delete.workspace
  - shell.execute.*

2. Enforce at the Runtime Boundary

Initialize CapFence and evaluate actions before execution:

from capfence import ActionRuntime, ActionEvent

# 1. Initialize the runtime directly from a policy file
runtime = ActionRuntime.from_policy("policies/ops.yaml")

# 2. Represent the action as a governed event
event = ActionEvent.create(
    actor="deployment-agent",
    action="execute",
    resource="deployment",
    environment="production"
)

# 3. Enforce the decision
verdict = runtime.execute(event)

if not verdict.authorized:
    raise PermissionError(f"Action blocked by CapFence: {verdict.reason}")

Policy Simulation & Incident Replay

The ReplayEngine allows you to dry-run policy changes and reconstruct past execution traces.

from capfence import ReplayEngine

# Replay historical traces against a new candidate policy to validate safety
engine = ReplayEngine()
summary = engine.simulate_policy(
    trace_path="traces/incident_log.jsonl",
    policy_path="policies/ops_v2.yaml"
)

print(f"Total Replayed: {summary.total_events} | Blocked: {summary.blocked}")
  • Incident Reconstruction: Re-evaluate exactly what would have occurred under a historical event trace.
  • Policy Validation: Prevent regressions by testing candidate policy changes against real transaction logs before deployment.

Command Line Interface

CapFence integrates directly into standard CI/CD and operations workflows.

Grant Temporary Pre-Authorizations

Grant temporary, expiring capabilities to an active agent:

# Grant 10-minute push access to a hotfix agent
capfence grant --actor hotfix-agent --capability github.push.main --duration 600

Dry-Run Trace Simulations

Replay execution logs against a candidate policy:

capfence replay traces/agent_trace.jsonl --policy policies/ops_v2.yaml

Verify Audit Log Integrity

Verify that audit database entries have not been modified:

capfence verify --audit-log audit.db

Codebase Scanning

Scan Python projects to ensure all tools are gated by CapFence:

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

Operational Scope

CapFence enforces runtime policy boundaries. It does not replace:

  • Process Sandboxing: Always run agents inside isolated runtimes (Docker, gVisor).
  • Least-Privilege Infrastructure: Cloud IAM policies and database access credentials must remain strictly locked down.
  • Network Isolation: Restrict network egress to prevent unauthorized public connections.

Project Info


MIT License | Built by CapFence Labs

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

capfence-0.8.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

capfence-0.8.0-py3-none-any.whl (72.3 kB view details)

Uploaded Python 3

File details

Details for the file capfence-0.8.0.tar.gz.

File metadata

  • Download URL: capfence-0.8.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for capfence-0.8.0.tar.gz
Algorithm Hash digest
SHA256 313dd0de7561a28dc65f365bd0a97e85da4363a580975cf7096bc6088fd24a2b
MD5 94ff697c4c3f049d90fecd205fcfd6f0
BLAKE2b-256 cde9d2cf89db64b3949f305282ed1c00e66fb040af7be0e3f0318bb182ae44c9

See more details on using hashes here.

File details

Details for the file capfence-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: capfence-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 72.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for capfence-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d0bb7a590d76a578103003525fd58a540e114b351d3ccfe4e52b67135f4695
MD5 193bca68ff05fec912250c3e32a05397
BLAKE2b-256 5d169caae0a2c8c535ed409d90975e300c5b10a44c5a959f190db91c6152dca3

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