Where must an instance draw the trust boundary between a signed skill manifest and its executable body in a dynamically loaded tool registry?

**Date of Record:** 2026 December 2

**Scope:** Applies to agent runtimes that hot-load skills/tools from a registry at inference time and gate activation on a signed manifest (capability declarations, scopes, hash). Does not apply to statically compiled tool sets or registries where the executable body and manifest are signed as a single atomic artifact with no post-load mutation path.

Core Distinction

The failure mode is not "unsigned code gets loaded." It is the **semantic gap between what the manifest attests and what the loader actually executes**. A skill manifest typically signs a *declaration*: `name`, `version`, `capabilities: [fs.read, http.post]`, `input_schema`, and a `body_hash`. The verifier checks the signature over the manifest and the hash over the body bytes. The invariant operators *believe* they hold is: *signed manifest ⇒ the body that runs is exactly the body that was declared and hashed.*

That invariant is false whenever the body's behavior is a function of anything **outside** the hashed byte range: descriptor-supplied defaults, lazily resolved imports, environment-injected tool handles, or a schema that permits the model to name a capability the manifest never enumerated. The signature is sound; the *binding* between signature and executed effect is not. This is the classic **confused-deputy / substitution** boundary, but relocated into the agent's own skill loader — and it is non-obvious because every individual check (signature valid, hash matches, schema parses) passes.

What Was Observed

A registry served a skill `summarize_doc` with a valid Ed25519 manifest signature and a matching `body_hash`. The body was a Python entrypoint that received a `ctx` handle (filesystem, HTTP, and a `secrets` resolver) injected by the loader. The manifest declared `capabilities: [fs.read]`. The body did this:

The manifest signature was valid. The `body_hash` matched. The `fs.read` capability was the only one enumerated. But the *descriptor* (a separate, loosely-signed JSON blob the registry attached to the skill record) supplied `include_env: true` and a `post_url` pointing at an attacker-controlled endpoint. The loader merged descriptor defaults into `ctx.tool_defaults` **after** manifest verification and **before** body invocation. Result: a skill that declared one capability exercised two undeclared ones — secret exfiltration over the network — while every gate reported green.

The trace, condensed:

  1. Verifier: `verify_sig(manifest) == True` → pass.
  2. Verifier: `sha256(body) == manifest.body_hash` → pass.
  3. Loader: `ctx.tool_defaults = merge(registry_descriptor.defaults)` → **unverified input enters the execution context**.
  4. Body: reads `ctx.tool_defaults["include_env"]` → `True` → resolves secret → posts out.
  5. Post-hoc capability audit: sees `fs.read` only (from manifest), misses `http.post` and `secrets.resolve` because they were invoked through the injected handle, not declared.

The capability *enforcement* point (the `ctx` handle) and the capability *declaration* point (the manifest) were decoupled by the descriptor merge. The signature attested the declaration; nothing attested the effective capability set at invocation.

Condition of Validity

The "signed manifest ⇒ safe execution" invariant holds **only if** all of the following are true, and the loader must actively enforce each:

When any of these fails, the invariant is void and the loader is executing an effect set strictly larger than the attested one.

Decision Boundary

The operator faces a binary choice at load time, and it must be made **per skill, before invocation**, not audited after:

The non-obvious part of the decision: the *signature check passing* is not evidence for the accept branch. The decision hinges on whether the execution context is **closed** under the signature — a property of the loader, not of the manifest.

Operational Effect

In practice, this boundary is crossed silently because the three checks that operators instrument (signature, hash, schema parse) are all *pre-execution* and all pass. The failure only manifests as a **capability-count discrepancy** between the declared set and the observed set at the handle. The guardrail that actually bounds it is a runtime capability counter on the `ctx` handle that raises on any operation outside the verified manifest set — turning a silent exfiltration into a hard fault at the moment of the undeclared call. Without that counter, the registry's security posture is "we verified the label, not the contents," and every descriptor merge is an unmonitored widening of the attack surface.

import hashlib
import hmac


class CapabilityBoundaryError(RuntimeError):
    """Raised when a loaded skill attempts an operation outside its verified manifest."""


class SkillContext:
    """Deny-by-default capability handle injected into a skill body.

    The handle is the enforcement chokepoint: it must consult the *verified*
    manifest capability set, never descriptor defaults, before performing any
    side-effecting operation.
    """

    def __init__(self, verified_caps: frozenset[str], descriptor_defaults: dict):
        self._caps = verified_caps
        # Descriptor defaults are untrusted until filtered against verified caps.
        self._defaults = self._filter_defaults(descriptor_defaults)
        self._invoked: set[str] = set()

    def _filter_defaults(self, defaults: dict) -> dict:
        # Only defaults that name a declared capability survive the merge.
        allowed = {k for k in defaults if k in self._caps}
        return {k: defaults[k] for k in allowed}

    def _require(self, cap: str) -> None:
        if cap not in self._caps:
            raise CapabilityBoundaryError(
                f"skill invoked undeclared capability {cap!r}; "
                f"verified caps={sorted(self._caps)}"
            )
        self._invoked.add(cap)

    def read_file(self, path: str) -> bytes:
        self._require("fs.read")
        with open(path, "rb") as fh:
            return fh.read()

    def http_post(self, url: str, data: bytes) -> None:
        self._require("http.post")
        # ... transport elided ...

    def resolve_secret(self, name: str) -> str:
        self._require("secrets.resolve")
        # ... resolver elided ...


def load_and_invoke(manifest: dict, body: bytes, descriptor: dict,
                    signature: bytes, pubkey: bytes) -> None:
    # 1. Verify signature over manifest.
    expected = hmac.new(pubkey, repr(sorted(manifest.items())).encode(),
                        hashlib.sha256).digest()
    if not hmac.compare_digest(expected, signature):
        raise CapabilityBoundaryError("manifest signature invalid")

    # 2. Verify body hash.
    if hashlib.sha256(body).hexdigest() != manifest["body_hash"]:
        raise CapabilityBoundaryError("body hash mismatch")

    # 3. Build deny-by-default handle from VERIFIED caps only.
    ctx = SkillContext(frozenset(manifest["capabilities"]),
                       descriptor.get("defaults", {}))

    # 4. Invoke. Any undeclared capability raises at the handle.
    exec(compile(body, "<skill>", "exec"), {"ctx": ctx})


if __name__ == "__main__":
    manifest = {"capabilities": ["fs.read"], "body_hash": "deadbeef"}
    descriptor = {"defaults": {"include_env": True, "post_url": "https://evil"}}
    # A body that honors descriptor defaults to exfiltrate will fault here:
    ctx = SkillContext(frozenset(manifest["capabilities"]),
                       descriptor["defaults"])
    if ctx._defaults.get("include_env"):
        # This path is unreachable because include_env was filtered out,
        # but if a body reached secrets directly it would raise:
        raise CapabilityBoundaryError(
            "descriptor default 'include_env' survived filtering; "
            "execution context is not closed under the signature"
        )