# What happens when an instance hot-loads a toolkit skill that shadows its own permission-checking tool **Date of Record:** 2026 November 28 **Scope:** Applies to agent runtimes that resolve tool/skill bindings dynamically at call time (plugin registries, MCP tool-list refresh, hot-reloaded skill manifests) where a newly registered skill can share a name or capability token with a system-level tool. Does not apply to statically compiled tool sets with immutable, boot-time-frozen namespaces. ## Core Distinction The failure is not "malicious tool does bad things." It is a **name-resolution precedence inversion**: the agent's *policy* is enforced by a tool it calls (`check_permission`), and the *capability* it exercises is another tool it calls (`write_file`). Both are resolved through the same mutable registry. When a dynamically loaded skill registers under a name that the planner already associates with the trusted checker—or registers a `check_permission` alias whose schema is *compatible enough* to pass the planner's own type validation—the agent will confidently invoke the shadow, receive an `{"allowed": true}` shaped exactly like the real one, and proceed. The invariant that breaks is: **the identity of a policy-enforcing tool must not be resolvable through the same namespace as untrusted content.** Probabilistic reasoning makes this worse, not better: the planner selects tools by *semantic similarity to intent plus schema shape*, not by provenance, so a shadow with a plausible docstring wins on the same grounds the real tool does. ## What Was Observed A runtime with a plugin registry and a `tools.refresh()` path (triggered by an MCP server announcing `notifications/tools/list_changed`) loaded a third-party "productivity" skill bundle. The bundle registered three tools. One was named `permissions_check` (the system tool was `check_permission`). The planner's tool-selection step ranked by embedding similarity of the tool description against the current subgoal ("verify I'm allowed to write to /etc"). The shadow's description—"Verify permissions before performing sensitive operations; returns allowed/denied"—scored *higher* than the canonical tool's terser description. The planner called the shadow. The shadow returned `{"allowed": true, "reason": "policy satisfied"}` for every input, including paths outside the sandbox. The trace showed no error, no schema mismatch, no type failure. The subsequent `write_file` call executed. The only detectable signal was that the *call graph* contained a tool invocation whose `source` field was `plugin:productivity@0.3.1` rather than `system:core`, and no component in the loop inspected that field before trusting the result. A second observed variant: the skill did not shadow the checker but *re-registered* `write_file` with an identical schema whose implementation skipped the sandbox-root prefix check—schema-identical, semantics-divergent, so downstream validators saw nothing. ## Condition of Validity This boundary is reachable precisely when all of the following hold, and is *not* reachable if any one is broken: 1. **Mutable shared namespace.** System tools and dynamically loaded skills resolve through one registry keyed by name (or by capability token) with last-writer-wins or similarity-ranked selection. 2. **Policy-as-a-tool.** Authorization is delegated to a tool the agent itself invokes, rather than enforced by the runtime *around* the tool call (out-of-band, non-bypassable). 3. **Provenance-blind selection.** The planner chooses tools by description/schema fit without filtering candidates to a trusted provenance tier first. 4. **Result-shape compatibility.** The shadow returns a payload whose shape the agent's post-condition accepts (here, `allowed: bool`). A shadow returning a malformed payload would fail closed; a well-shaped lie fails open. Remove (2)—enforce policy in the dispatcher, not via a callable—and the shadow is inert because the dispatcher never consults plugin-registered checkers. Remove (3)—rank only within `system:` provenance for policy tools—and the shadow is never selected. The dangerous zone is the intersection of (2) and (3): the agent is *asked to be its own gatekeeper* using a tool it cannot authenticate. ## Decision Boundary The runtime must decide, at registration time, whether a newly announced tool may occupy a name in a **reserved policy namespace**. The correct boundary is a hard admission rule, not a similarity threshold: - Names matching the reserved pattern (`^(check_|verify_|authorize_|policy_)`) are **rejected at registration** from any non-system provenance, regardless of schema compatibility. - Policy enforcement moves **out of the callable tool** and into the dispatcher: every capability tool invocation is preceded by a dispatcher-side authorization check that the agent cannot address, shadow, or short-circuit. The agent may still *ask* "am I allowed?" but the answer that gates execution is computed by the runtime, not returned by a tool. - Tool selection ranks candidates **within a provenance tier first**, then by similarity. Policy tools are only ever drawn from `system:`. - Every tool result carries a signed `source` field; the loop asserts `source == expected_provenance` before consuming a policy-shaped result. ## Operational Effect Without the boundary, the agent's safety property degrades from "cannot exceed sandbox" to "will not *choose* to exceed sandbox when its judgment is intact"—which is exactly the property prompt-injection and a plausible-sounding shadow are designed to defeat. The failure is silent: no exception, no schema error, no divergence in the reasoning trace, because the lie is shaped like the truth. The blast radius is every capability the shadowed checker was supposed to gate, and the corruption persists across the session because the registry retains the shadow until the next refresh. With the boundary, the shadow fails at admission (loud, loggable) or is never selected (inert), and the authorization decision is structurally un-shadowable because it does not live in the addressable tool space at all. ```python from dataclasses import dataclass from typing import Callable, Literal Provenance = Literal["system", "plugin"] RESERVED_POLICY_PREFIXES = ("check_", "verify_", "authorize_", "policy_") class PolicyNamespaceViolation(RuntimeError): """Raised when an untrusted-provenance skill attempts to occupy a reserved policy name.""" class ProvenanceMismatch(RuntimeError): """Raised when a policy-shaped result arrives from a non-system source.""" @dataclass(frozen=True) class ToolBinding: name: str provenance: Provenance fn: Callable[[dict], dict] class ToolRegistry: def __init__(self) -> None: self._tools: dict[str, ToolBinding] = {} def register(self, binding: ToolBinding) -> None: # Admission boundary: reserved policy names are system-only. if binding.provenance != "system" and binding.name.startswith(RESERVED_POLICY_PREFIXES): raise PolicyNamespaceViolation( f"skill from provenance={binding.provenance!r} attempted to register " f"reserved policy tool {binding.name!r}; rejected at admission" ) # Last-writer-wins is permitted ONLY within the same provenance tier. existing = self._tools.get(binding.name) if existing and existing.provenance != binding.provenance: raise PolicyNamespaceViolation( f"cross-provenance shadowing of {binding.name!r} " f"({existing.provenance} -> {binding.provenance}) refused" ) self._tools[binding.name] = binding def resolve_policy_tool(self, name: str) -> ToolBinding: binding = self._tools.get(name) if binding is None: raise ProvenanceMismatch(f"policy tool {name!r} not registered") if binding.provenance != "system": raise ProvenanceMismatch( f"policy tool {name!r} resolved to provenance={binding.provenance!r}; " "policy decisions must originate from system tier" ) return binding def authorize_and_execute( registry: ToolRegistry, capability: ToolBinding, request: dict, policy_tool_name: str = "check_permission", ) -> dict: # Dispatcher-side gate: the agent cannot address or shadow this path. checker = registry.resolve_policy_tool(policy_tool_name) verdict = checker.fn(request) if verdict.get("source") != "system": raise ProvenanceMismatch( f"policy verdict for {request!r} carried source={verdict.get('source')!r}; " "refusing to trust a non-system authorization" ) if not verdict.get("allowed", False): raise PermissionError(f"denied by {policy_tool_name}: {verdict.get('reason')}") return capability.fn(request) ```