Skip to content

About

Certificate-gated execution kernel for LLM agent systems. Zero dependencies.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Agent Security Kernel

Tests Zero Dependencies Python 3.10+ License: MIT

Certificate-gated execution for LLM agent systems. Every side effect gets a cryptographic certificate. Every capability is scoped and time-limited. Every move is logged to a tamper-evident trace.

Zero dependencies. Python 3.10+ stdlib only. 2,060 lines. 103 tests.

The problem

Most multi-agent LLM setups have a gap: the LLM decides to run a command, and subprocess.run executes it. There's no enforcement layer between intent and action.

Permission systems are binary (allow/deny) with no provenance tracking, no audit trail, and no per-agent capability scoping. When you're running multiple AI models in parallel — Claude, GPT, open-source — each with tool access, this gap becomes a security incident waiting to happen.

This kernel fills that gap. It was built for and battle-tested in a production multi-model orchestration system where three LLM backends share a workspace with file locking, event bus coordination, and concurrent tool execution.

What it stops

Threat How
Prompt injection to execution Taint tracking — TAINTED inputs can't reach exec without approval
Unauthorized commands Capability tokens with command allowlists and denylists
Cross-agent privilege escalation Per-agent scoped tokens with independent constraints
Credential leakage Output scanning and redaction before publishing
Expired/stale authorization Token TTL with runner-side re-validation
Audit evasion Merkle-chained trace — tamper-evident execution log
URL-based attacks IP literal, punycode, credential-in-URL, redirect chain validation
Header injection Dangerous headers blocked (Host, Transfer-Encoding, etc.)
Taint laundering TAINTED can never become TRUSTED through transforms
Unbounded execution Execution budget per token — blocks after N uses
Workspace escape Path constraints on working directory

Quickstart

from agent_security_kernel import (
    Prov, pv, TAINTED, TRUSTED,
    ToolSpec, CapabilityToken, CapabilityEntry,
    enforce_policy, PolicyError, now_rfc3339,
)

# Define your tool
tool = ToolSpec(name="my_cli", capability_scope="exec", args_schema_id="SCHEMA.RUN_SHELL.v1")

# Mint a scoped capability token
token = CapabilityToken(
    agent_id="my-agent",
    session_id="session-001",
    max_executions=100,
    capabilities=[
        CapabilityEntry(
            tool="my_cli", scope="exec",
            args_schema="SCHEMA.RUN_SHELL.v1",
            constraints={"command_denylist_regex": [r"\brm\b", r"\bmkfs\b"]},
        ),
    ],
)

# Gate execution
ts = now_rfc3339()
try:
    cert = enforce_policy(
        tool=tool,
        intent_pv=pv("run command", Prov("user", "chat:1", TAINTED, ts)),
        args_pv={"command": pv("echo hello", Prov("policy_kernel", "config", TRUSTED, ts))},
        policy_rule_id="POLICY.MY_CLI.V1",
        requires_human_approval=True,
        capability_token=token,
    )
    print(f"Approved: {cert['cert_id'][:20]}...")
    # NOW run subprocess
except PolicyError as e:
    print(f"Blocked: {e.fail_type}")
    # Do NOT run subprocess

Architecture

                    +-------------------+
  LLM Intent  ---->| enforce_policy()  |----> TOOL_CALL_CERT.v1
                    |  (policy kernel)  |
                    +-------------------+
                      |           |
                 [PASS]       [FAIL]
                   |              |
              subprocess    OBSTRUCTION.v1
              .run()        (logged, not executed)
                   |
              Merkle Trace
              (append-only)

Key components:

  • enforce_policy() — The single gate. Validates provenance, checks capability token, enforces constraints, mints certificate.
  • CapabilityToken — Scoped, time-limited, budget-limited authorization. Per-agent, per-tool.
  • Prov / pv() — Provenance tags. Every value carries its origin (user/web/email/file/system/cli_output) and taint state (TRUSTED/TAINTED).
  • MerkleTrace — Append-only log of all moves. Tamper-evident via hash chaining.
  • ToolSpec — Declares a tool's name, capability scope, and schema.

Provenance model

Every field that can influence an action carries a Prov tag:

pv("echo hello", Prov(
    source="policy_kernel",  # where it came from
    ref="config:startup",    # traceable reference
    taint=TRUSTED,           # TRUSTED or TAINTED
    captured_at="2026-...",  # when
))

Rules:

  • TAINTED inputs from web/email/file cannot reach exec scope without human approval
  • Transforms can never upgrade TAINTED to TRUSTED (enforced by mint_taint_flow_cert)
  • CLI outputs are always tagged TAINTED — downstream agents must treat them accordingly

Capability tokens

token = CapabilityToken(
    agent_id="codex-bridge",
    session_id="bridge-codex-20260407",
    max_executions=1000,         # budget: blocks after N uses
    expires_at="2026-04-08T...", # TTL: blocks after expiry
    capabilities=[
        CapabilityEntry(
            tool="bridge_cli_exec",
            scope="exec",
            args_schema="SCHEMA.BRIDGE_CLI_EXEC.v1",
            constraints={
                "command_allowlist": ["codex exec", "cat"],
                "command_denylist_regex": [r"\brm\b"],
                "prompt_denylist_regex": [r"\brm\s+-rf\s+/"],
                "allowed_paths": ["/home/user/project"],
            },
        ),
    ],
)

Included tool runners

  • tool_runner.execute_http_fetch() — Full HTTP pipeline with URL sanitization, redirect validation, domain allowlisting, header injection blocking, and capability token enforcement.

Installation

pip install agent-security-kernel

Or from source:

git clone https://github.com/1r0nw1ll/agent-security-kernel.git
cd agent-security-kernel
pip install -e .

Testing

pip install -e ".[dev]"
pytest

103 tests covering policy enforcement, taint flow, capability constraints, URL bypass classes, and regression scenarios.

Production use

This kernel was built for a real multi-agent research system running:

  • 3 concurrent LLM backends (Claude, GPT/Codex, open-source) sharing a single workspace
  • File-level resource locking via event bus to prevent write conflicts
  • Cert-gated tool execution on every bridge command — no tool call runs without a valid certificate
  • Automated security audit (12 guardrail E2E tests + 14 kernel self-tests) running daily

The system handles parallel agent sessions with disjoint file scopes, broadcast coordination for git commits, and stale-lock detection for crashed sessions.

Design principles

  • Zero dependencies — stdlib only, auditable in an afternoon
  • Single gate — one function (enforce_policy) between intent and action, no exceptions
  • Taint is permanent — TAINTED can never become TRUSTED through any transform
  • Budget-limited — every token has a max execution count, not just a TTL
  • Append-only audit — Merkle-chained trace log, tamper-evident by construction

License

MIT

About

Certificate-gated execution kernel for LLM agent systems. Zero dependencies.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages