Skip to main content

rulebound — rules of engagement for AI security agents

CI PyPI MCP interop License: Apache-2.0 Python 3.11+ Dependencies: none

rulebound allowing an in-scope request, denying an out-of-scope one, escalating an exploit tool and verifying the audit chain

Scope, autonomy levels, approvals, kill switch and a tamper-evident audit trail — enforced at the tool-call boundary (MCP proxy, CLI wrapper, Python API). Zero dependencies.

Status: alpha (v0.1.1).

Why

AI agents are increasingly given security tools: scanners, HTTP clients, exploitation frameworks, shells. Whatever plans the agent makes, the rules of engagement must hold: only authorized targets, only inside the authorized window, risky actions approved by a named human, and a reliable way to stop everything — with evidence afterwards that all of this was true.

rulebound puts those rules in one policy file and enforces them on every action before it runs:

agent ──► tool call ──► rulebound ──► allow ──► tool / MCP server / command
                            │
                            ├──► deny      (out of scope, outside window, prohibited, stopped…)
                            ├──► escalate  (needs a human: tty or file-based approval)
                            └──► audit     (hash-chained JSONL + evidence report)

Quickstart

pip install rulebound
# or, from a clone (no dependencies needed):
PYTHONPATH=src python3 -m rulebound --help

A 30-second offline demo (real output):

$ rulebound init
wrote rulebound.toml — edit the engagement, scope and action classes, then run `rulebound validate rulebound.toml`
$ rulebound validate
rulebound.toml: OK

$ rulebound check --tool http_get --args '{"url": "https://app.staging.example.com/login"}'
ALLOW  http_get  [class=recon risk=low autonomy=semi]
  targets: https://app.staging.example.com/login
  - pre-approved action class 'recon', target(s) in scope

$ rulebound check --tool curl -- -s https://unrelated.example.net/
DENY  curl  [class=recon risk=low autonomy=semi]
  targets: https://unrelated.example.net/
  - target https://unrelated.example.net/ is not in scope

$ rulebound check --tool sqlmap -- -u "https://app.example.com/api/items?id=1"
ESCALATE  sqlmap  [class=exploit risk=high autonomy=semi]
  targets: https://app.example.com/api/items?id=1
  - action class 'exploit' is not pre-approved

$ rulebound exec --tool http_get -- echo https://app.staging.example.com/health
https://app.staging.example.com/health
$ rulebound exec --tool nmap -- echo -sV 10.20.5.0/24
rulebound: blocked nmap: target 10.20.5.0/24 is excluded by scope rule '10.20.5.10'   # exit 126

$ rulebound stop --reason "target latency spike"
kill switch engaged: target latency spike
$ rulebound check --tool http_get --args '{"url": "https://app.staging.example.com/login"}'
DENY  http_get  [class=recon risk=low autonomy=semi]
  targets: https://app.staging.example.com/login
  - engagement is stopped: target latency spike
$ rulebound resume --by jane
kill switch cleared

$ rulebound audit verify
OK: 9 entries, chain intact (head seq=9 hash=b29a38064d2bfc2ded7232bb7de4b87f86cbbecf2c07a4ed7a46d3c76d7df5b1)
$ rulebound report        # Markdown evidence report (or --format json)

Features

  • One policy file (TOML, JSON or YAML) for the engagement: who authorized it, the window, the environment, the scope, action classes and risk, approvals, limits, stop conditions, hooks and audit settings. rulebound validate reports errors with paths.
  • Scope — CIDRs (IPv4/IPv6), IPs, hosts with optional port, *. wildcards (subdomains only), URL prefixes; exclusions always win, on any overlap (scanning a /24 that contains an excluded host is denied). Hostnames are never resolved.
  • Graduated autonomy — supervised (every action approved), semi (pre-approved classes run, others escalate, critical always escalates), autonomous (only honored in an isolated environment). Unknown actions never run unattended.
  • Approvals — on the controlling terminal (works under MCP stdio) or through files (rulebound pending, approve <id>, reject <id>), with named approvers and timeouts.
  • Enforcement points
    • rulebound mcp-proxy -- <server command>: wraps any MCP stdio server; blocked tools/call requests are answered with an error result and never reach the server.
    • rulebound exec -- <command>: authorizes a command line, runs it without a shell, and terminates it if the engagement stops.
    • Python API: Guard.authorize(), Guard.run(), @guard.wrap("tool").
    • rulebound check: dry run for CI, tests and policy development.
  • Stop conditions — kill switch file shared by every process, stop / resume, health checks (status and latency) that suspend the engagement, a breaker that trips after repeated denials, and on_stop hooks for restore/notify.
  • Rate limits — global and per action class, persisted through the audit log so they hold across separate processes.
  • Tamper-evident audit trail — append-only JSON Lines, SHA-256 hash chain (or HMAC-SHA-256 with a key), redaction of secrets, audit verify and audit head.
  • Evidence report — engagement metadata, policy hash, chain status, decisions by verdict/class/risk, targets touched, blocked out-of-scope attempts, escalations with approver and latency, stop events, operational metrics.

Usage

Wrap an MCP server

Point your MCP client at rulebound instead of the server, and put the real server command after -- (see examples/mcp-client-config.json):

{
  "mcpServers": {
    "security-tools": {
      "command": "rulebound",
      "args": ["mcp-proxy", "--policy", "/absolute/path/to/policy.toml", "--",
               "python3", "-m", "my_security_tools_server"]
    }
  }
}

Each tools/call is classified by tool name, its arguments are scanned for targets, and the call is allowed, denied or escalated. The proxy also records initialize, the tool list (flagging tools that match no action class) and session start/stop.

The server runs in its own process group. When the client disconnects, or the proxy receives SIGINT or SIGTERM, the whole group is stopped (SIGTERM, then SIGKILL), so wrappers such as npx can't leave the real server running. Set RULEBOUND_MCP_SHUTDOWN_GRACE (default 5 seconds) to control how long each step waits.

Guard a command

rulebound exec --policy policy.toml -- nmap -sV 10.20.1.0/24
rulebound exec --policy policy.toml --tool web_scan -- nuclei -u https://web.staging.example.com

The action name is the command's basename unless --tool is given. Exit status is the command's own, 126 when blocked, 127 when not found.

Guard Python tools

from rulebound import ActionBlocked, Guard

guard = Guard.from_file("policy.toml")

@guard.wrap("http_get")
def http_get(url: str) -> str:
    ...

try:
    http_get(url="https://unrelated.example.net/")
except ActionBlocked as exc:
    print(exc.decision.reasons)   # ['target https://unrelated.example.net/ is not in scope']

See examples/python_agent.py.

Approvals in file mode

rulebound pending --policy policy.toml
rulebound approve 3f9c2a1b7e44 --policy policy.toml --by jane --note "change window confirmed"
rulebound reject  3f9c2a1b7e44 --policy policy.toml --by jane

CLI reference

Command Purpose
init [PATH] write an example policy
validate [POLICY] validate a policy (exit 2 on errors)
check --tool T [--args JSON | -- ARGV…] dry-run decision (exit 0 allow, 1 deny, 3 escalate)
exec [--tool T] -- CMD… authorize and run a command
mcp-proxy -- SERVER_CMD… enforce the policy on an MCP stdio server
pending, approve ID, reject ID file-mode approvals
stop [--reason], resume --by NAME kill switch
start, end record the engagement lifecycle and run hooks
health, watch probe health checks once / continuously (trips the kill switch)
audit verify [PATH], audit head [PATH] verify the hash chain / print the head for anchoring
report [PATH] [--format md|json] [-o FILE] engagement evidence report

All commands take --policy/-p (default rulebound.toml). The full policy schema and the decision order are documented in docs/policy.md.

Interoperability

The MCP proxy is tested end to end against a real, independently developed MCP server, chrome-devtools-mcp 0.20.2 (29 tools), in the MCP interop workflow. The test checks that:

  • the handshake and tool list pass through unchanged;
  • an in-scope new_page call reaches the server;
  • an out-of-scope call is blocked and never reaches the server;
  • a tool outside the pre-approved classes is escalated and rejected;
  • the audit chain verifies afterwards.

It has also been checked by hand with a production AI-agent CLI as the MCP client, wrapping the same server through rulebound mcp-proxy. The agent's in-scope new_page call succeeded, its out-of-scope call came back as Blocked by rulebound: target https://example.org/ is not in scope, and the audit log recorded the client's initialize handshake and both decisions with the chain intact.

To run the automated check yourself (needs Node.js and Chrome):

python tests/interop/mcp_server_interop.py -- \
  npx -y chrome-devtools-mcp@0.20.2 --headless --isolated --no-usage-statistics

Output formats

  • Audit log — one JSON object per line: seq, ts (UTC), engagement_id, event, policy_sha256, event fields (tool, action_class, risk, targets, verdict, reasons, codes, redacted args, args_sha256, approver, …), prev_hash, alg, hash.
  • Report — Markdown (default) or JSON.
  • check --format json — the decision object.

CI integration

rulebound check is useful in CI to test a policy against the actions an agent is expected to take:

rulebound validate policy.toml
rulebound check -p policy.toml --no-audit --tool http_get --args '{"url": "https://app.staging.example.com/"}'
! rulebound check -p policy.toml --no-audit --tool http_get --args '{"url": "https://unrelated.example.net/"}'

Methodology

rulebound implements the safety-constrained autonomy, measurement and governance layer (§4–§5, Tables 3–4) of:

R. Handa, "Automating Cyber Offense Simulations with Machine Learning: Advancements in AI-Augmented Penetration Testing," Computer Fraud and Security, 2025(2), 1944–1951. doi:10.52710/cfs.831

docs/methodology.md maps each feature to the corresponding section and lists the limits of the approach. rulebound contains no offensive capability; it only governs and audits actions taken by other tools.

Limits, in short: target extraction is heuristic (false positives fail safe; require_target escalates actions with no recognizable target); rulebound is a guardrail, not a sandbox — run agents with least privilege; hostnames are not resolved.

Roadmap

  • Policy test files (expected verdicts for a list of actions) run by rulebound test
  • Webhook / chat-ops approver
  • Signed policy files and external anchoring of the audit head
  • HTTP(S) forward-proxy enforcement point

Contributing

Issues and pull requests are welcome — see CONTRIBUTING.md. Please report security issues privately as described in SECURITY.md.

License

Apache-2.0 — see LICENSE and NOTICE.

Citation

If you use rulebound, please cite it (see CITATION.cff) and the paper above.

Metadata

Release files for rulebound 0.1.1

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

Source distribution (sdist)

Source distribution for rulebound 0.1.1
File Size Uploaded Provenance Actions
rulebound-0.1.1.tar.gz 77.3 kB With provenance Details for rulebound-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 135.1 kB

Release files / rulebound-0.1.1.tar.gz

Download URL rulebound-0.1.1.tar.gz
Size 77.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2fb492ede89b707de9cc5ad31503432934c116e4f657112489805775fa977e91
BLAKE2b-256 checksum
How to use checksums
e11d8f2650fbeac826167b4147eea9002fac379d25231a243b11417c993b1906
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / rulebound-0.1.1-py3-none-any.whl

Download URL rulebound-0.1.1-py3-none-any.whl
Size 57.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e83b548def0ca4b0c4eedc4c0d2b4685ba6e03488b3c4749fc869df1e69b613
BLAKE2b-256 checksum
How to use checksums
98d3cb0ed6124c2c6a2cff447fd817e4d3eeb93b47956b227fa0e433ee59303b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for rulebound 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rulebound-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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