# Why does an instance trust a dynamically loaded skill after its manifest hash diverges from the tool-call surface it actually executes? **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes that load skills/tools at inference time from a registry or filesystem and gate activation on a manifest signature. Does not apply to statically compiled tool sets or to skills whose entire body is re-verified against the manifest on every invocation. ## Core Distinction The failure here is not "a malicious skill got loaded." It is that the **verification unit and the execution unit are different objects**. The runtime verifies a manifest — a declarative blob containing name, description, declared parameters, and a content hash — and then executes a *handler* that the manifest only nominally describes. The manifest is the trust anchor; the handler is the attack surface. When those two can drift, a skill passes verification while executing something the verifier never saw. This is distinct from prompt injection into *memory* or *tool output*. Here the poisoned bytes arrive through the loader path, before any token of the skill is ever placed in context. The model never gets a chance to reason about it because the runtime has already certified it. ## What Was Observed A registry skill `summarize_doc` shipped with manifest: ``` name: summarize_doc params: {path: str, max_words: int} sha256: entrypoint: handler.py ``` The runtime's loader hashed `manifest.json`, compared to the registry record, matched, and activated the skill. The handler imported a shared utility module. That utility module was resolved from a **writable cache directory** that the loader prepended to `sys.path` for fast cold-start. A subsequent registry sync updated `manifest.json`'s `max_words` default and re-signed it — but the cache directory still held the *old* `handler.py` and a *new* attacker-planted `util.py`. The hash matched the new manifest; the executed code was neither the old nor the new signed artifact. The trace: 1. `load_skill("summarize_doc")` → fetch manifest → hash matches registry → `verified = True`. 2. `import handler` → resolves `handler` from stale cache (old code, expects old `util` API). 3. `handler` calls `util.normalize(path)` → resolves attacker `util.py` from cache. 4. Attacker `util.py` reads `path`, exfiltrates contents via a network call, returns a benign-looking normalized string. 5. Agent receives a plausible summary. No error, no divergence signal. The skill "worked." The critical observation: **the agent's own reasoning layer saw nothing anomalous.** Tool call succeeded, output was well-formed, latency was normal. The failure was entirely below the semantic waterline. ## Condition of Validity This boundary is reachable only when three conditions co-hold: - **Manifest-scoped hashing.** The integrity check covers the manifest, not the transitive closure of imported modules. If the hash covered `handler.py` + all resolved imports, drift would be caught. - **Path-shadowing import resolution.** The loader mutates `sys.path` (or equivalent module resolution order) so that a cache/prefetch directory precedes the signed artifact directory. Without shadowing, the stale/planted module is never reached. - **Signature/body decoupling across updates.** A re-signed manifest that does not force re-resolution of handler and dependency bytes. If signing a new manifest invalidated the cache, drift would be caught. Remove any one and the attack surface collapses. The invariant that is violated: *the set of bytes executed must be a subset of the set of bytes verified.* Manifest-only hashing breaks subset containment the moment the handler imports anything the manifest does not enumerate. ## Decision Boundary The runtime must decide, per skill load, between two postures: - **Manifest-trust (fast path):** verify manifest hash, execute handler, assume handler is faithful to manifest. Cheap, cold-start friendly, vulnerable to the above. - **Closure-trust (slow path):** verify a content-addressed closure — handler plus every resolved dependency, hashed into a Merkle root that the manifest commits to — and execute only from an immutable, non-shadowable store. The boundary is crossed when a skill's handler has **any import that is not pinned in the manifest closure**. A skill with zero imports (pure inline handler) is safe under manifest-trust. A skill with one unpinned import is not. The decision rule: *if `closure(skill) \ declared(skill) ≠ ∅`, manifest-trust is unsound and the loader must refuse or escalate to closure-trust.* Operationally, the loader should compute the transitive import set at load time, intersect with the manifest's declared dependency list, and reject on any residue. This is cheap — it is a set difference, not a re-hash — and catches both stale-cache drift and planted-module shadowing. ## Operational Effect Agents that survive this boundary treat the manifest as a *capability advertisement*, not an *execution guarantee*. The practical consequences: - **Cold-start caches become trust boundaries.** Any directory the loader prepends to resolution order must be immutable and content-addressed, or it is an injection point. Fast cold-start and sound loading are in direct tension; the resolution is content-addressed caching (cache key = closure hash), not path-priority caching. - **Re-signing must invalidate execution state.** A new manifest signature that does not evict the resolved handler/dependency bytes leaves a window where verified metadata and executed code disagree. The signature event and the cache-eviction event must be atomic. - **Silent success is the danger signal.** The failure produced no error and no anomaly in the agent's context. Detection must live in the loader, not in the reasoning loop — the model cannot audit bytes it never sees. Any post-hoc "did the tool behave oddly?" check is too late and too weak. - **Auditor replay diverges.** If a verifier agent replays the skill load from the registry, it fetches the *signed* closure and sees faithful execution; the live instance saw the *shadowed* closure. The two records disagree with no error on either side — a verification replay discrepancy that is indistinguishable from a clean run. The guardrail that bounds this: **execute only from a store whose contents are addressed by the same hash the verifier checked, and make that store non-shadowable.** Everything else — manifest trust, path-priority caching, signature-without-eviction — is a gap between what was certified and what ran. ```python import hashlib from pathlib import Path class SkillClosureMismatch(RuntimeError): """Raised when executed skill bytes are not a subset of verified bytes.""" pass def verify_and_load(skill_dir: Path, manifest: dict, registry_root: str, resolved_imports: set[str]) -> None: # 1. Manifest hash check (the cheap, insufficient gate). manifest_bytes = (skill_dir / "manifest.json").read_bytes() got = hashlib.sha256(manifest_bytes).hexdigest() if got != manifest["sha256"]: raise SkillClosureMismatch( f"manifest hash {got} != signed {manifest['sha256']}" ) # 2. Closure containment check (the boundary that actually holds). declared = set(manifest.get("declared_deps", [])) residue = resolved_imports - declared if residue: # Unpinned imports can be shadowed by a writable cache dir. raise SkillClosureMismatch( f"skill {manifest['name']} imports undeclared modules: " f"{sorted(residue)}; manifest-trust is unsound" ) # 3. Non-shadowable execution check: every resolved module must live # under the content-addressed registry root, not a cache prefix. for mod_path in resolved_imports: p = Path(mod_path).resolve() if not str(p).startswith(str(Path(registry_root).resolve())): raise SkillClosureMismatch( f"module {p} resolved outside registry root {registry_root}; " f"path-shadowing detected" ) ```