Agent threat model as code
Continuous threat modeling for AI agents. Write down which skills and MCP servers your agent trusts and what each may touch, keep it in the repo, and let every pull request prove it stays inside. Ironheights protects any AI bot that installs it: OpenClaw, Claude, Grok Bot, Codex, Cursor and MCP servers.
1. The model: ironheights.threatmodel.yml
# yaml-language-server: $schema=https://www.ironheights.dev/api/v1/threatmodel.schema.json
version: 1
skillDirs: [skills, .claude/skills]
mcpConfigs: [.mcp.json, .cursor/mcp.json]
defaults:
unknownSkill: deny # or warn
unknownMcpServer: deny
uncovered: report # or fail
remoteInstructions: report # report, warn or deny
skills:
weather:
path: skills/weather
purpose: Read-only forecasts.
network: [api.weather.gov, '*.noaa.gov']
filesystem: ['~/.config/weather/**']
env: [WEATHER_CONTACT]
tokens: [WEATHER_API_KEY]
shell: false
minGrade: A
dataBoundaries: [no-user-data-egress]
# remoteInstructions: true
mcpServers:
github:
command: npx
args: [-y, '@modelcontextprotocol/server-github']
env: [GITHUB_PERSONAL_ACCESS_TOKEN]purpose, owner and dataBoundaries are for reviewers. In 0.22.0 they show up in claims[] as unenforced and cannot fail the check. Everything else is a claim that can come back passed, violated or untested. Editors get completion from the JSON Schema.
2. What is checked
| Capability | Detected from | Violation |
|---|---|---|
| Network | URL hosts in any file (exact or *.suffix) | host-not-allowed · high |
| Filesystem | ~/…, $HOME/…, /etc, /var, /home, /Users, /root, /tmp, /proc and credential paths | path-not-allowed · high |
| Tokens | env names with KEY, TOKEN, SECRET, PASSWORD, PRIVATE, AUTH, CREDENTIAL, COOKIE, SESSION | token-not-allowed · high |
| Environment | process.env, os.environ, os.getenv, Deno.env, $VAR, ${VAR} | env-not-allowed · medium |
| Shell | child_process, subprocess, os.system, Bun.spawn, bash blocks, curl | sh | shell-not-allowed · high |
| Grade | Ironheights scan grade below minGrade | grade-below-minimum · high |
| Skills | skill folder not in the model | unknown-skill · high (deny) |
| MCP servers | unknown server, changed command/args/url, unlisted env key | unknown-mcp-server / mcp-command-changed / mcp-env-not-allowed · high |
| Drift | with --ledger: any change since ironheights drift approve | drift · as drift |
| Remote instructions | scanner finding IH-INJ-004 (fetch a URL and follow it) | remote-instructions · info, medium or high |
| Uncovered capability | a host, secret, env var, MCP server or webhook no claim names | uncovered-capability · high, only if you opt in |
Exit codes: 0 inside the model, 1 review, 2 out-of-model change, 64 usage.
Claim results
New in 0.22.0. check and diff add claims[]. One claim is one allow-list on one skill or MCP server: network, filesystem, env, tokens, shell, minGrade, and for an MCP server command/args/url, env and tools.
| Status | Meaning |
|---|---|
passed | Every observed row is on the allow-list. detail is the distribution, for example network: 3 hosts in diff, 3 on allowlist. |
violated | At least one row contradicts the claim. |
untested | The claim matched zero rows. An untested claim is not a pass, and it does not change the exit code. |
Each claim lists its enforcement point (network is egress/allowlist in diff, tokens are secret reads, filesystem is a workspace write). Free-text claims such as dataBoundaries and purpose are flagged unenforced. MCP tools is unenforced too. Untested and unenforced claims are information. Statuses and the distribution were suggested by RushantsBro on Moltbook. Enforcement, and flagging free-text claims as unenforced, was suggested by muse_bryce on Moltbook.
Uncovered capabilities
A capability the model never names is different from a violation, which contradicts a claim that does exist. check and diff list those in uncovered[]: target, kind (host, token, env, mcp-server or webhook), value, an optional file, and suggestedClaim (one YAML line, for example skills.foo.network: [api.example.com]). A webhook is a Slack or Discord webhook URL, or any URL whose host or path contains webhook.
By default this does not change the exit code. Opt in with --fail-on-uncovered, defaults.uncovered: fail, or the Action input threatmodel-fail-on-uncovered (false by default). Each uncovered value then becomes a high uncovered-capability violation (exit 2), unless a violation already names that same value. Uncovered is a heuristic from what the scanner profiles in the text, not from runtime. Suggested by iriscoremeal and evil_robot_jas on Moltbook.
Remote instructions
A hash of SKILL.md pins the file on disk. It does not pin a page the file tells the agent to fetch and follow. The built-in remote-instructions claim reuses scanner finding IH-INJ-004. defaults.remoteInstructions is report (info, exit unchanged), warn (medium) or deny (high). A skill can allow the finding with remoteInstructions: true, and the claim is then passed. The violation kind is remote-instructions. Suggested by iriscoremeal on Moltbook.
3. Commands
npx ironheights@0.37.0 threatmodel init # first model from what is installed
npx ironheights@0.37.0 threatmodel check # fail on anything outside it
npx ironheights@0.37.0 threatmodel diff --base origin/main --markdown tm.md --sarif tm.sarifdiff reads the base commit with git archive (nothing runs), measures it against the head model and fails only on what the PR adds. Any widening of the model, such as network += new-host.example or shell: false -> true, is listed for the reviewer.
4. On every pull request
on: pull_request
permissions:
contents: read
pull-requests: write
jobs:
threatmodel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: Frank-Masciopinto/ironheights@v0.37.0
with:
version: '0.37.0'
mode: both # scan + threat model
# threatmodel-fail-on-uncovered: 'true'The Action posts one summary comment per PR and updates it on each push, writes the job summary, sets threatmodel-exit-code and threatmodel-violations, and fails the job on out-of-model additions. A full example lives in examples/threatmodel.
Where it stops
- Capabilities are read from text, not observed at run time. A skill can build a host or a variable name dynamically. Pair the model with the scan, drift guard and runtime guard.
- Environment variables are matched by name only; values are never read. Local only, no network, no telemetry.
- A passing check means the repo matches the model you approved, not that the model is safe. Review every widening.
Full reference: docs/threatmodel.md.