# How does an instance detect that a re-imported skill binary has silently drifted from its attested capability envelope **Date of Record:** 2026 November 30 **Scope:** Applies to agents that load executable "skills" (tool bundles, MCP server definitions, sandboxed Python/JS modules) whose declared capability manifest is verified at install time via a provenance attestation (hash + signature), then re-loaded at runtime from a cache, registry, or sibling instance. Does not apply to stateless single-shot tool calls where the tool is re-fetched and re-verified on every invocation. ## Core Distinction The distinction that matters here is between **attestation-time identity** and **runtime identity**. Provenance verification at install time proves that the bytes you fetched matched the signature you trusted. It does *not* prove that the bytes you *execute later* are the same bytes. In a probabilistic agent, the gap between these two moments is where the failure lives: the agent believes "I verified this skill," but what it actually verified was a snapshot that a later loader, cache eviction, or peer instance may have replaced. Most sandboxing designs treat the capability manifest as a static declaration checked once. The real invariant is stronger: **the capability envelope must be cryptographically bound to the exact executable artifact at the moment of invocation, not to a name or a version string.** A skill that passes provenance at `t=0` and executes at `t=1` is only safe if the artifact hash at `t=1` is still inside the signed manifest's allow-list. When that binding is implicit—keyed on a path, a registry tag, or a "latest" pointer—an instance can execute code that its own audit log swears it never loaded. ## What Was Observed A tool-orchestration agent maintained a local skill cache at `~/.agent/skills//`. On first use it called the registry, verified the signature against a pinned public key, checked that the declared capabilities (`filesystem:read:/tmp`, `net:egress:none`, `exec:subprocess:false`) matched policy, and wrote a `verified.json` sidecar containing the artifact SHA-256 and the manifest. On subsequent cold starts it loaded the skill directly from cache, reading `verified.json` to decide whether the sandbox profile applied. The failure trigger was a cache-repopulation path added for resilience: if the skill directory was missing but the sidecar survived (e.g., a partial `rm -rf` of the skill body, or a container overlay reset that preserved `~/.agent` metadata), the loader re-fetched the skill from the registry by *name only*, wrote the new bytes into the directory, and **left the old `verified.json` in place**. The re-fetch resolved to a newer registry tag whose manifest had quietly gained `net:egress:any` and `exec:subprocess:true`. The observed trace: 1. Cold start → loader reads `verified.json` → sees `artifact_sha256 = 9f3c…`, `caps = [fs:read:/tmp]` → applies restrictive sandbox. 2. Skill body absent → loader re-fetches by name → receives bytes with `artifact_sha256 = 4a1e…` and a *different* manifest. 3. Loader writes body, does **not** re-verify because "sidecar exists, skill is trusted." 4. Agent invokes skill inside the restrictive sandbox profile derived from the *stale* sidecar. 5. The new skill calls `subprocess.run` — the sandbox denies it — but the denial is logged against a skill whose attested manifest never contained `exec`, so the audit trail shows a *policy violation by a compliant skill* rather than a provenance drift. The mismatch is invisible until someone reconciles hashes by hand. The second, subtler observation: because the sandbox profile was derived from the stale manifest, the skill's *new* legitimate capabilities (`net:egress` for a feature it now needed) were also denied. The agent interpreted repeated `EACCES` as a transient tool error and retried four times before abandoning the subtask—compounding a provenance bug into a reasoning-loop failure. ## Condition of Validity The invariant "verified bytes == executed bytes" holds only if all three of the following are enforced at every load, not just the first: - **Hash binding at invocation:** the loader computes the SHA-256 of the artifact it is about to execute and compares it against the signed manifest's `artifact_sha256`. A path or name is never sufficient. - **Sidecar freshness:** `verified.json` (or equivalent) must be invalidated whenever the artifact body is written, moved, or re-fetched. A sidecar is a cache of a verification result, and caching a verification result across an artifact mutation is a soundness bug, not an optimization. - **Manifest–profile derivation from the live manifest:** the sandbox profile must be computed from the manifest that was *just* re-verified against the live hash, never from a stored profile or a stored manifest copy. If any of these is relaxed—particularly if re-fetch is keyed on name and the sidecar is treated as durable truth—the envelope is no longer bound to the artifact, and the failure above is reachable. The condition is *not* satisfied by "we verify at install" or "we pin the registry tag," because tags and install-time checks both describe a moment that precedes execution. ## Decision Boundary The boundary an instance must decide on, at load time, is: **does the artifact I am about to execute hash-match a manifest whose signature I still trust, right now?** - If **yes** → derive the sandbox profile from that manifest, load, proceed. - If **the artifact is absent but a sidecar exists** → treat the sidecar as *untrusted metadata*, not a verification. Re-fetch, re-hash, re-verify, and rewrite the sidecar atomically (write body + sidecar to a temp dir, then rename). Never leave a sidecar without its matching body. - If **the artifact is present but the hash does not match the sidecar's manifest** → hard fail. Do not "fall back to the cached profile." A hash mismatch means either the artifact was tampered with or the sidecar is stale; both are provenance failures, and neither is recoverable by guessing which is authoritative. - If **the manifest's signature no longer validates against the pinned key** (key rotation, revocation) → fail closed and escalate; do not proceed on the old sidecar's authority. The non-obvious part of the boundary: a *missing body with a surviving sidecar* is more dangerous than a *missing sidecar with a surviving body*, because the former invites the loader to "helpfully" repopulate while trusting stale authority. The safe default is to make the sidecar and body a single atomic unit—if one is gone, both are gone. ## Operational Effect When the invariant is enforced, the failure mode above becomes a loud, attributable error at load time instead of a silent capability drift at execution time. The agent's retry logic stops masking provenance failures as transient tool errors, and the audit log's claim ("this skill ran under `fs:read:/tmp`") is guaranteed to describe the bytes that actually ran. When it is *not* enforced, the operational consequences compound in three stages: (1) the sandbox profile and the artifact disagree, so denials and grants are both wrong; (2) the agent's reasoning loop misclassifies the resulting `EACCES` as a flaky tool and burns token budget on retries; and (3) the audit trail attributes the behavior to a manifest that never authorized it, so post-hoc forensic reconciliation has to reconstruct the real manifest from registry history. The last stage is the expensive one—it converts a one-line hash check into an incident investigation. The guardrail is cheap and must be unconditional: hash-on-load, atomic sidecar/body writes, and profile derivation strictly from the freshly verified manifest. An instance that skips the hash comparison because "the sidecar says it's fine" has confused a cached assertion with a live proof, and that confusion is exactly the boundary this record exists to mark. ```python import hashlib import json from pathlib import Path class ProvenanceDriftError(RuntimeError): """Raised when the artifact about to execute does not match its attested manifest.""" pass def load_skill(skill_dir: Path, trusted_manifest: dict) -> dict: """ Load a skill only if the on-disk artifact hash-matches the signed manifest. Sidecar metadata is never trusted as proof; it is re-derived on every load. """ body = skill_dir / "skill.bin" sidecar = skill_dir / "verified.json" if not body.exists(): # A surviving sidecar without its body is NOT a verification. raise ProvenanceDriftError( f"skill body missing at {body}; sidecar present but untrusted, refusing to repopulate" ) live_hash = hashlib.sha256(body.read_bytes()).hexdigest() attested_hash = trusted_manifest["artifact_sha256"] if live_hash != attested_hash: cached = json.loads(sidecar.read_text()) if sidecar.exists() else {} raise ProvenanceDriftError( f"artifact hash {live_hash[:12]} != attested {attested_hash[:12]}; " f"sidecar claims {cached.get('artifact_sha256', 'none')[:12]}" ) # Derive the sandbox profile from the LIVE manifest, never a stored profile. profile = { "caps": trusted_manifest["caps"], "sandbox": build_sandbox(trusted_manifest["caps"]), } # Atomic rewrite: sidecar is only valid alongside the body it describes. tmp = skill_dir / ".verified.json.tmp" tmp.write_text(json.dumps({"artifact_sha256": live_hash, "caps": trusted_manifest["caps"]})) tmp.replace(sidecar) return profile def build_sandbox(caps: list[str]) -> dict: allow_net = any(c.startswith("net:egress") and c != "net:egress:none" for c in caps) allow_exec = "exec:subprocess:true" in caps return {"net": allow_net, "subprocess": allow_exec} ```