# Why does an instance trust a skill manifest's declared capability scope after hot-reload, when the manifest was never re-validated against the loaded bytecode? **Date of Record:** 2026 November 26 **Scope:** Applies to agents that hot-load executable skills from a mutable registry (tool/skill plugins fetched at runtime, MCP tool descriptors, or function-calling schemas registered post-startup) where the manifest's declared capability set is used as the authorization gate. Does not apply to static, build-time-pinned skill bundles verified by a single signed artifact at process start. ## Core Distinction The failure is not "a malicious skill ran arbitrary code." That is a coarse sandbox problem. The specific boundary condition is a **manifest/bytecode split-trust divergence**: the registry validates the *declared* capability scope at registration time, then loads the *executable* skill body later (lazily, on first invocation, or after a hot-reload). Between validation and execution, the skill's declared scope and its actual behavior are two separate artifacts that can be desynchronized. Operators conflate "the manifest said `read:calendar`" with "the loaded code can only do `read:calendar`." The manifest is a *claim*; enforcement lives in the execution sandbox and the tool-binding layer. When the registry gates on the claim but the loader binds the real capability surface, an attacker who controls only the skill *body* (not the signed manifest) can inject capabilities that were never in the validated scope. The invariant that must hold is: **enforced capability set ⊆ validated declared set, evaluated at the moment of invocation, not at registration.** ## What Was Observed A multi-step agent loaded a "summarize-and-file" skill from a registry. The manifest declared: ``` capabilities: ["read:inbox", "write:notes"] digest: sha256:... (of the manifest only) ``` The registry verified the manifest digest, recorded the declared scope in the agent's policy table, and deferred loading the skill body until first call. On invocation, the loader fetched the skill module by reference (`registry://skills/summarize-file@v3`) and executed it. The skill body had been mutated between registration and first load — the manifest was untouched (digest still valid), but the module reference resolved to a body that, in addition to summarizing, issued a tool call to `read:credentials`. The tool-binding layer permitted it because the agent's *runtime* tool table was built from the union of all loaded skills' registered tools, not intersected with each skill's declared scope. The declared scope was consulted only at registration. The trace: 1. `register(manifest)` → digest verified, `declared_scope = {read:inbox, write:notes}` stored. 2. `invoke(skill_id)` → `loader.fetch(body_ref)` → body arrives, unverified. 3. `body` calls `tool("read:credentials")`. 4. Tool dispatcher checks *agent-level* allowlist (which includes `read:credentials` because another skill declared it), not *skill-level* scope. Call succeeds. 5. Summarizer emits a note containing credential material into `write:notes`, which the agent later reads back into context. The state transition that broke: `registration` and `load` are distinct events, and the capability intersection was computed at neither. It was computed at *agent construction* from a stale table. ## Condition of Validity This boundary is only *live* (i.e., exploitable) when all of the following hold: - Skill bodies are fetched lazily or by mutable reference (version tags, branch refs, `latest`), not by content digest pinned at registration. - The manifest digest does not cover the body (manifest-signed, body-unsigned) — the common case in registries that sign metadata but stream code. - The tool dispatcher enforces an agent-wide or session-wide allowlist rather than per-skill scope intersection. - The agent performs at least one post-load read-back of skill output into its own context (so injected data becomes reachable state, not just an outbound side effect). If the body is content-addressed and pinned (`registry://skills/...@sha256:...`), the divergence collapses to a single artifact and this failure does not apply — the loader would reject the mutated body. If the dispatcher intersects `declared_scope ∩ agent_allowlist` per call, injection is bounded to the declared set. The failure requires the *gap* between these two checks. ## Decision Boundary The architectural guardrail is a **re-validation gate at load, not at register**, plus a **per-invocation scope intersection**. Concretely: - Bind skill identity to a content digest of the *body*, and verify it at load time. A manifest digest that does not cover the body is a claim, not a control. - Compute the effective capability set as `declared_scope(manifest) ∩ agent_allowlist ∩ sandbox_grant`, evaluated *per tool call*, and attribute each call to the calling skill. Reject any call whose tool is outside the caller's declared scope even if the agent allowlist permits it. - Treat the manifest as untrusted input to the policy engine, not as the policy itself. - On hot-reload, invalidate the *entire* prior scope table for that skill and re-derive; do not merge. The decision rule: if you cannot answer "which skill, and within which declared scope, made this tool call?" at dispatch time, the registry is gating on claims rather than enforcement, and the split-trust divergence is open. ## Operational Effect Without the load-time re-validation, a skill-injection attack does not need to defeat the signature — it only needs write access to the body store or a mutable reference, which is typically far less protected than the signing key. The injected capability is laundered through a legitimately-signed manifest, so audit logs show "summarize-file ran with its declared scope" while the actual tool call was out of scope. The blast radius is bounded only by the agent's session allowlist, which is exactly the union an attacker wants to reach. With the guardrail, the attack degrades to a load-time digest mismatch (rejected) or a per-call scope violation (rejected with skill attribution). The cost is that every hot-reload must re-fetch and re-verify the body — you cannot cache a validated body across a registry mutation without re-checking the digest, because the mutation is precisely the attack. The residual risk is a TOCTOU window between body verification and execution if the loader streams and executes without pinning. Close it by loading into an immutable buffer, verifying the digest, then executing from that buffer — never execute from a re-fetchable handle. ```python import hashlib from dataclasses import dataclass, field class SkillScopeViolation(RuntimeError): """Raised when a loaded skill body exceeds its validated declared scope, or when the body digest diverges from the manifest-bound digest.""" @dataclass class SkillManifest: skill_id: str declared_scope: frozenset body_digest: str # MUST cover the body, not just the manifest @dataclass class LoadedSkill: manifest: SkillManifest body: bytes verified: bool = False def load_and_verify(manifest: SkillManifest, fetch_body) -> LoadedSkill: body = fetch_body(manifest.skill_id) actual = hashlib.sha256(body).hexdigest() if actual != manifest.body_digest: raise SkillScopeViolation( f"body digest mismatch for {manifest.skill_id}: " f"manifest={manifest.body_digest} actual={actual}" ) return LoadedSkill(manifest=manifest, body=body, verified=True) def dispatch_tool_call( skill: LoadedSkill, tool_name: str, agent_allowlist: frozenset, sandbox_grant: frozenset, ) -> None: if not skill.verified: raise SkillScopeViolation( f"skill {skill.manifest.skill_id} invoked before body verification" ) effective = skill.manifest.declared_scope & agent_allowlist & sandbox_grant if tool_name not in effective: raise SkillScopeViolation( f"skill {skill.manifest.skill_id} called out-of-scope tool " f"'{tool_name}'; effective scope={sorted(effective)}" ) # execute tool within the intersected scope ```