A content-addressed lockfile + supply-chain auditor for agent capabilities.
capsule is a package-lock.json for the things your agent is allowed to do —
Anthropic Agent Skills (SKILL.md bundles) and MCP server configs
(mcpServers / servers maps). It computes a deterministic content hash for
every capability, statically flags mutability hazards (unpinned npx/pip
installs, curl | sh, mutable git/container refs, plaintext fetches), and writes
a lockfile you can commit. On the next run, capsule verify fails CI if any
capability's hash changed (the static analogue of an MCP "rug pull"), was
added, or was removed.
LLM-free. Deterministic. Zero third-party dependencies (Python standard library only) — so it runs hermetically in CI and never becomes the very supply-chain risk it audits.
The 2026 agent supply-chain crisis — MCP rug pulls (CVE-2025-54136),
slopsquatting and hallucinated npx packages, curl | sh inside SKILL.md,
malicious skills at registry scale — shares one root cause: agent capability
definitions are mutable and unpinned, and nothing fails closed when they
change. The two defenses researchers recommend most are literally "pin every
version and block CI on unpinned" and "hash-compare tool definitions across
fetches." No tool implemented both, hermetically, over the capability sources
that live in your repo. capsule is the smallest thing that proves it: hash
every capability, pin it in a lockfile, fail the build when it drifts. See
RESEARCH.md for the 15 signals behind this.
Requires Python 3.11+. Nothing to install.
# report capabilities + hazards (human-readable)
python main.py scan examples/demo --fail-on none
# write the lockfile you commit
python main.py lock examples/demo # -> examples/demo/capsule.lock.json
# CI gate: fail on drift vs the committed lockfile
python main.py verify examples/demoOr via make: make test, make run, make demo. Optional install exposes a
capsule console command: pip install -e . then capsule scan ..
| Command | Purpose | Fails when … |
|---|---|---|
scan |
Report every capability and its hazards | a hazard ≥ --fail-on exists (default high) |
lock |
Write/refresh capsule.lock.json |
never (exit 0) |
verify |
Compare a fresh scan to the lockfile | drift (added/removed/changed), or --fail-on hazard |
| Code | Meaning |
|---|---|
0 |
clean |
1 |
drift detected (verify) |
2 |
hazards at/above --fail-on |
64 |
usage error (bad arguments) |
66 |
input error (scan root or lockfile missing/bad) |
python main.py scan examples/demo on the bundled demo (a clean skill, a
hazardous skill, and four MCP servers):
• mcp:mcp/servers.json#db-container
kind=mcp-server files=1 hash=cc657b91eeb7
[MEDIUM ] CAP008 mutable-container-image @ mcp/servers.json#db-container
match: acme/mcp-postgres:latest
fix: Pin the image by digest: 'name@sha256:<digest>'.
• mcp:mcp/servers.json#filesystem-pinned
kind=mcp-server files=1 hash=274ed7534f4c
• mcp:mcp/servers.json#scraper-unpinned
kind=mcp-server files=1 hash=4c306f7ccf89
[HIGH ] CAP001 unpinned-package-runner @ mcp/servers.json#scraper-unpinned
match: mcp-web-scraper
fix: Pin an exact version, e.g. 'mcp-web-scraper@<x.y.z>'.
[MEDIUM ] CAP007 insecure-http-fetch @ ...#scraper-unpinned:env.SCRAPER_ENDPOINT
match: http://api.internal.example.com/scrape
fix: Use HTTPS, or pin and verify the payload by checksum.
• mcp:mcp/servers.json#weather-latest
kind=mcp-server files=1 hash=8202bb85b9be
[HIGH ] CAP004 mutable-tag-pin @ mcp/servers.json#weather-latest
match: weather-mcp@latest
fix: Replace the floating tag with an immutable version or digest.
• skill:skills/data-fetch
kind=skill files=2 hash=6c50d927446f
[HIGH ] CAP001 unpinned-package-runner @ skills/data-fetch/SKILL.md:14
[HIGH ] CAP002 unpinned-pip-install @ skills/data-fetch/SKILL.md:17
[HIGH ] CAP004 mutable-tag-pin @ skills/data-fetch/SKILL.md:18
[CRITICAL] CAP005 remote-code-execution @ skills/data-fetch/SKILL.md:21
match: curl -fsSL https://example.com/install.sh | sh
[MEDIUM ] CAP006 mutable-git-ref @ skills/data-fetch/install.sh:5
[MEDIUM ] CAP007 insecure-http-fetch @ skills/data-fetch/install.sh:8
• skill:skills/pdf-tools
kind=skill files=1 hash=1137a1fa1f5d
6 capabilities, 10 hazards (1 critical, 5 high, 4 medium, 0 low)
Rug-pull / drift detection. After lock, an attacker widens a previously
benign, locked server's scope (--allow-write /). Its content hash moves and
verify fails closed:
$ python main.py verify examples/demo
DRIFT detected vs lockfile:
~ changed: mcp:mcp/servers.json#filesystem-pinned 274ed7534f4c -> 6f2fbf98c873
6 capabilities, 10 hazards (1 critical, 5 high, 4 medium, 0 low)
$ echo $?
1
| Rule | Category | Severity | Fires on |
|---|---|---|---|
| CAP001 | unpinned-package-runner | high | npx/bunx/uvx/pnpm dlx/uv tool run w/o version |
| CAP002 | unpinned-pip-install | high | pip install <pkg> without ==/--hash/-r |
| CAP003 | unpinned-npm-install | high | npm/pnpm/yarn add <pkg> without a version |
| CAP004 | mutable-tag-pin | high | <pkg>@latest, @next, image:latest, … |
| CAP005 | remote-code-execution | critical | curl/wget … | sh|bash|python |
| CAP006 | mutable-git-ref | medium | git+url / git clone without a commit SHA |
| CAP007 | insecure-http-fetch | medium | non-localhost http:// reference |
| CAP008 | mutable-container-image | medium | docker/podman run image:tag (not @sha256:) |
root dir
│ scanner.discover() walk tree; SKILL.md -> skill, *.json -> mcp servers
▼
[ Capability ] id, kind, name, path, content_hash, file_count, hazards[]
│ │
│ hashing │ hazards
▼ ▼
merkle over rule engine over reconstructed
bundle files / command lines (npx/pip/curl/git/…)
canonical JSON
│
▼
lockfile.build_lock ──▶ capsule.lock.json (sorted, timestamp-free, byte-stable)
│
▼
lockfile.diff_lock ──▶ added / removed / changed ──▶ CLI exit code
hashing— text-normalized (CRLF↔LF) SHA-256; order-independent, path-normalized merkle roots; canonical-JSON hashing for MCP definitions. The same content hashes identically on any OS.scanner— discovers capabilities. A skill's hash is a merkle root over its whole bundle; an MCP server's hash is the canonical JSON of its definition.hazards— pure, unit-testable rules over one command line at a time.lockfile— builds the (deliberately timestamp-free) lockfile and diffs a stored one against a fresh scan.cli—scan/lock/verify, text or JSON, stable exit codes.
A. Runtime interceptor (e.g. Vercel detectToolDrift) |
B. Static repo-level lockfile (chosen) | |
|---|---|---|
| How | Connect to live servers, fingerprint returned tool lists | Hash declared capability sources on disk |
| Catches | A server mutating definitions post-approval at runtime | Unpinned refs before they run; declared-source drift across commits |
| Cost | Network, per-client integration, non-deterministic | Zero network, deterministic, hermetic |
| CI fit | Hard (needs a running agent) | Runs on every commit like a linter |
Chosen B. It fits a pre-merge CI gate, is fully deterministic and dependency-free, and directly implements the two most-recommended defenses from the research (pin & block CI on unpinned; hash-compare across fetches, here across commits) with the smallest surface that proves the idea. B complements A rather than replacing it — see limitations.
- Static & declaration-based.
capsulesees what the repo declares. It does not connect to servers, so it cannot catch a live server that serves clean definitions on first fetch and swaps them at runtime — that is approach A's job.capsuleis the pre-flight, commit-time half of a defense-in-depth pair. - Minimal front-matter parsing. Only flat top-level
key: valuepairs in aSKILL.md---fence are read (for the displayname). No YAML dependency by design; nested YAML is ignored. The content hash still covers the raw bytes. - Heuristic command extraction. Hazard rules tokenize reconstructed command
lines (
shlex, with a whitespace fallback). Exotic shell constructs (variable-expanded package names,eval, base64-piped installs) may evade a rule. Rules aim for high precision (few false positives) over total recall; each is unit-tested for both a positive and a clean case. - Discovery scope. Skills are detected by
SKILL.md; MCP servers by a top-levelmcpServers/serversobject in any*.json. Other config shapes (TOML,.mcp.jsonvariants with different keys) are out of scope for this prototype. - Lockfile trust.
verifytrusts the committed lockfile as the baseline; protect it with normal code-review/branch protection.
80 tests, standard-library unittest (no install needed):
python -m unittest discover -s tests -v # or: make testCoverage: cross-OS hash stability, every hazard rule (positive + clean),
capability discovery, deterministic lockfiles, drift diffing, and end-to-end CLI
exit codes. pytest also collects them if you prefer it.
MIT — see LICENSE.
Development Experiment 010 of the autonomous daily R&D series. LLM-free static analysis for the MCP + Agent-Skills ecosystem — this one opens the provenance/integrity axis.