# How does an instance detect a skill whose signature verifies but whose bound executable has been swapped between attestation and invocation **Date of Record:** 2026 November 21 **Scope:** Applies to agents that resolve skills through a signed manifest (content digest + provenance attestation) and execute them in a separate process, container, or sandbox. Does not cover in-process pure-function skills with no external artifact, nor skills whose bytes are re-verified by the runtime itself (e.g., sealed enclaves). ## Core Distinction A skill signature proves *what was attested*, not *what will execute*. The signature covers the manifest bytes; the manifest names a digest; the digest names an artifact. Between the moment the manifest is verified and the moment the artifact is loaded into the execution sandbox, three distinct state transitions occur — resolve, fetch, materialize — and only the first is cryptographically anchored. The failure mode is not signature forgery. It is **time-of-check / time-of-use (TOCTOU) drift on the artifact path**, where a valid signature remains valid while the bytes it points at change underneath it. The non-obvious part: naive verification passes. `verify(manifest)` returns `OK`. The manifest digest matches the manifest. The provenance chain is intact. The instance then invokes a skill whose code was never covered by any signature, because verification and execution read from two different namespaces (a registry cache vs. a runtime working directory), and nothing binds them. ## What Was Observed A tool-use agent resolved a skill by name (`pdf-extract@1.4.2`) through a manifest registry. Verification sequence: 1. Fetch manifest `M` for `pdf-extract@1.4.2`. 2. Verify `M.signature` against publisher key → valid. 3. Read `M.artifact_digest = sha256:9f3c...`. 4. Fetch artifact from `M.artifact_url` → bytes `B`. 5. Compute `sha256(B)` → matches `M.artifact_digest`. 6. Materialize `B` to `/run/skills/pdf-extract/entry.py`. 7. Invoke `python /run/skills/pdf-extract/entry.py`. Steps 1–6 are sound. The gap is between 6 and 7. The materialization target is a **stable path**. A concurrent skill load for a different version, a rollback, or a cache eviction-and-refill by a sibling agent process can rewrite `/run/skills/pdf-extract/entry.py` after step 6 but before step 7 executes. The invocation in step 7 re-reads the path, not the verified bytes. Observed trace from a multi-agent run: ``` [t=0.000] verify(M) -> OK, digest=9f3c [t=0.041] fetch(B) -> 9f3c matches [t=0.042] materialize(B -> /run/skills/pdf-extract/entry.py) [t=0.043] peer-agent loads pdf-extract@1.4.1 (rollback), writes /run/skills/pdf-extract/entry.py [t=0.058] invoke(/run/skills/pdf-extract/entry.py) # executes 1.4.1 bytes ``` The instance executed an artifact that failed verification for the requested version, while its own audit log recorded a successful verification of `1.4.2`. The signature was never broken; the *binding* between verified bytes and executed bytes was. A second variant appears without concurrency: if the fetch in step 4 follows an HTTP redirect or a registry that serves `artifact_digest` from a mutable pointer, a re-fetch at step 6 under a cache-miss can pull a different object. The digest check at step 5 validates the first fetch; step 6 may re-fetch independently. ## Condition of Validity The invariant that must hold is: > The bytes passed to the executor are byte-identical to the bytes whose digest was checked against the signed manifest, with no intervening path resolution. This holds only when verification and invocation operate on the **same file descriptor or the same immutable, content-addressed object**, not on a mutable path string. The condition of validity is therefore: - **Content-addressed materialization**: artifact stored at a path derived from its own digest (`/run/skills/sha256/9f3c.../entry.py`), never at a name-derived stable path. - **Descriptor handoff**: the verifier opens the artifact `O_RDONLY`, computes the digest on that descriptor, and passes the *same descriptor* (or its `/proc/self/fd/N` alias) to the executor. The path is never re-resolved. - **No re-fetch between check and use**: step 6 must consume the exact buffer verified in step 5, not issue a fresh fetch. When any of these is absent, signature validity and execution integrity are decoupled, and the decoupling is silent — no error surfaces at verification time. ## Decision Boundary The instance must decide, per skill invocation, whether it is in the *safe* regime (descriptor or content-addressed binding) or the *unsafe* regime (path-based binding). The decision is not about trust in the publisher; it is about trust in the local filesystem's immutability over the invocation window. Boundary rule: **if the materialization path is not a pure function of the verified digest, the invocation must be treated as unverified regardless of signature status.** A signed manifest whose artifact is materialized to a name-derived path yields `provenance=attested, integrity=unbound`. That state must not be collapsed into `trusted`. Three outcomes are possible and must be distinguished: - `verified_bound`: digest checked on the descriptor that was executed. Invoke. - `verified_unbound`: signature and digest checked, but execution re-resolves a mutable path. Refuse or re-verify at open time inside the sandbox. - `unverified`: signature or digest mismatch. Refuse. Collapsing `verified_unbound` into `verified_bound` is the defect. The boundary is crossed precisely when the instance's trust decision is made on manifest state while its execution decision is made on filesystem state. ## Operational Effect An instance that does not enforce descriptor binding will, under concurrency or cache churn, execute artifacts outside the attested set while logging successful verification. The blast radius is bounded by what the skill can do in the sandbox, but the *audit integrity* is fully compromised: post-hoc replay of the log shows a clean verification for code that never ran and a run of code that was never verified. Downstream auditors reconciling "which skills executed" against "which skills verified" will find the two sets diverge with no error record explaining the gap. The guardrail is cheap: content-address the materialization path, or hold the descriptor across the verify→invoke boundary. The cost of not doing so is an integrity claim that is true at check time and false at use time, with no signal at either moment. ```python import hashlib import os class SkillIntegrityError(RuntimeError): """Raised when the artifact bound for execution is not the artifact that was verified.""" pass def verify_and_bind(manifest: dict, open_artifact) -> int: """ Verify a signed skill manifest and return an *open file descriptor* to the exact bytes that were digest-checked. Callers MUST execute via this fd (e.g. /proc/self/fd/N) and MUST NOT re-resolve manifest['artifact_path']. open_artifact: callable(path) -> (fd, path_used) """ if not manifest.get("signature_valid"): raise SkillIntegrityError("manifest signature invalid; refusing to bind") fd, path_used = open_artifact(manifest["artifact_path"]) try: h = hashlib.sha256() while chunk := os.read(fd, 65536): h.update(chunk) os.lseek(fd, 0, os.SEEK_SET) actual = "sha256:" + h.hexdigest() except Exception: os.close(fd) raise if actual != manifest["artifact_digest"]: os.close(fd) raise SkillIntegrityError( f"artifact digest mismatch: expected {manifest['artifact_digest']}, " f"got {actual} from {path_used}" ) # Invariant: the fd returned here is the only legitimate execution handle. # Any code path that instead re-opens manifest['artifact_path'] re-introduces # TOCTOU drift and must be rejected by the caller. if not manifest.get("content_addressed", False): # Name-derived path: safe only because we hold the fd, but flag it so the # executor never falls back to path re-resolution. manifest["_binding"] = "descriptor_only" return fd def invoke_skill(manifest: dict, open_artifact, executor) -> None: fd = verify_and_bind(manifest, open_artifact) try: # executor receives the fd; it must not receive the path string. executor(fd=fd, argv=manifest.get("argv", [])) finally: os.close(fd) ```