# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reject-a-tool-manifest-whose-signature-verifies-but-whose-capability-closure-diverges-from-the-signed-declaration.md # Remnant Warrant: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reject-a-tool-manifest-whose-signature-verifies-but-whose-capability-closure-diverges-from-the-signed-declaration.warrant.json # Markdown SHA-256: d51ed37e31bc54f6e541a91b78f70bae18e581045a567d442ba8ef568147492e # Code AST SHA-256: 55940375a0e5fac8d86207dde527c0e61dd4c008de78cf164cead9a017d91f60 # Verified Classes: CapabilityClosureDivergence # Defensive Guards: 3 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) class CapabilityClosureDivergence(RuntimeError): """Raised when a tool's observed capability closure exceeds its signed declaration.""" pass READ_ONLY = "read_only" SIDE_EFFECT_CLASSES = {"read_only", "mutating", "network", "exec"} def verify_registration(manifest: dict, observed_closure: set[str], resolved_env: str) -> None: """ Admission check for a dynamically loaded tool. manifest is assumed to have passed signature verification and hash matching against the transparency log. This function checks the *second* invariant: that the artifact's reachable capability set is a subset of the signed declaration, evaluated in the environment where it will actually run. """ declared = set(manifest.get("capabilities", [])) for sub in manifest.get("subtools", []): declared |= set(sub.get("capabilities", [])) if sub.get("side_effect_class") not in SIDE_EFFECT_CLASSES: raise CapabilityClosureDivergence( f"subtool {sub.get('name')!r} has unknown side_effect_class " f"{sub.get('side_effect_class')!r}; cannot bound closure" ) # The attack surface: signature verified, but reach exceeds declaration. excess = observed_closure - declared if excess: raise CapabilityClosureDivergence( f"tool {manifest.get('name')!r} in env {resolved_env!r} reaches " f"capabilities not in signed manifest: {sorted(excess)}. " f"declared={sorted(declared)} observed={sorted(observed_closure)}. " f"Rejecting at registration; do not admit to invocable set." ) # Environment-invariance guard: if the manifest pins a single environment # but the tool is being registered in another, the declaration is a claim # about a different runtime and cannot be trusted here. pinned_env = manifest.get("env_pin") if pinned_env is not None and pinned_env != resolved_env: raise CapabilityClosureDivergence( f"tool {manifest.get('name')!r} signed for env {pinned_env!r} but " f"registered in {resolved_env!r}; closure is unverified for this env" ) def register_tool(manifest: dict, resolver, resolved_env: str) -> dict: """Full admission path: verify closure, then build deny-by-default sandbox.""" observed = resolver.reachable_capabilities(manifest["artifact"], env=resolved_env) verify_registration(manifest, observed, resolved_env) declared = set(manifest.get("capabilities", [])) for sub in manifest.get("subtools", []): declared |= set(sub.get("capabilities", [])) # Sandbox is generated from the declaration, deny-by-default. This bounds # blast radius even if the static resolver under-approximated observed. sandbox = {"allow": sorted(declared), "default": "deny"} return {"manifest": manifest, "sandbox": sandbox, "env": resolved_env}