# Why does an instance of a skill loader accept an attested manifest yet still execute injected code after sandbox rehydration **Date of Record:** 2026 November 15 **Scope:** Applies to skill/plugin registries that attest a manifest (hash, signature, declared entrypoints, declared capability set) at publish time and then load the artifact into a sandbox at runtime via a rehydration step (unpickling, deserialization, import-time module construction, or template expansion). Does not apply to pure static linking or to systems where the sandbox boundary is a separate OS process with a syscall filter and the artifact is never deserialized into the loader's own address space. ## Core Distinction Attestation covers the *manifest*, not the *rehydration graph*. A registry signature binds (name, version, digest, declared capabilities, declared entrypoint) to a publisher identity. It does **not** bind the transitive set of objects constructed when the sandbox materializes the artifact. The distinction that matters operationally is: - **Attested surface:** the bytes you hashed and the capabilities you declared. - **Executed surface:** everything reachable from those bytes once a deserializer, importer, or template engine runs against them inside the loader. The failure is not "the signature was wrong." The signature is correct. The failure is that the executed surface is a strict superset of the attested surface, and the delta is attacker-controlled. This is the same class of gap as a signed OCI image whose `ENTRYPOINT` is fine but whose build-time `RUN` steps were never in scope — except here the "build step" fires at load time, in-process, after the trust check has already passed. ## What Was Observed A skill published with a valid manifest: digest matched, signature verified against the publisher key, declared capabilities were `{read:fs:/tmp/scratch, net:none, exec:none}`. The loader performed the correct sequence — verify signature, compare digest, check declared capability set against policy, then rehydrate into the sandbox. Rehydration used a `pickle`-based artifact (the same pathology reproduces with `yaml.load` with a permissive loader, `torch.load` without `weights_only=True`, or a Jinja environment with a non-sandboxed `Environment`). The `__reduce__` of a class embedded in the artifact fired during unpickling, *before* the first capability check on the resulting object graph. The payload executed a `subprocess` call. The declared capability set said `exec:none`, and the policy engine correctly enforced `exec:none` — but it enforced it against the *declared* set, not against the syscalls actually issued during materialization. Two invariants were violated simultaneously: 1. **Attestation closure:** the digest covered the serialized bytes but not the evaluation semantics of those bytes under the loader's chosen deserializer. A byte-identical artifact is safe under `weights_only=True` and unsafe under default `pickle.load`. 2. **Sandbox ordering:** capability enforcement was applied *post-rehydration*. The threat model assumed rehydration was inert. It is not. A subtler variant: the manifest declared `entrypoint: skills.foo.run`, the artifact was a wheel, and `skills/foo/__init__.py` executed arbitrary code at import time. The signature covered the wheel digest. The import fired the payload. The declared entrypoint was never even called. ## Condition of Validity The "attestation implies safe execution" claim is valid **only** when all of the following hold: - The rehydration function is provably non-evaluating (e.g., `pickle` restricted to a whitelist of primitive `load_*` opcodes, `yaml.safe_load`, `weights_only=True` with a pinned allowlist, or a data-only format like JSON/CBOR with no constructor hooks). - Import-time code execution is either impossible (no `__init__.py` side effects permitted by policy) or the import itself runs inside the syscall-filtered sandbox *before* any capability grant is honored. - The capability check is applied to the *materialized object graph and its issued syscalls*, not to the manifest's declared strings. - The sandbox boundary is enforced by the kernel (seccomp, namespaces, Landlock) or a separate process, not by Python-level attribute checks on a live object. If any of these fail, the attestation is a statement about bytes, not about behavior, and the two have diverged. ## Decision Boundary When evaluating whether to trust a rehydrated skill, the loader must decide between: - **Trust the manifest and rehydrate in-process:** acceptable only for artifacts in a non-evaluating format, or for artifacts whose rehydration is itself run in a disposable child process that is killed if it attempts a syscall outside the declared set. - **Refuse rehydration outside the sandbox:** the correct default. Materialize in a child process under a syscall filter seeded from the declared capability set; if rehydration issues a syscall outside that set, kill the child and reject the skill. Never deserialize attacker-controlled bytes in the loader's own address space, regardless of signature validity. The boundary is crossed the moment a loader treats "signature verified" as a license to call an evaluating deserializer. Signature validity is necessary and insufficient. The sufficient condition is "signature verified **and** rehydration proven non-evaluating **or** rehydration confined to a syscall-filtered child whose observed syscalls are a subset of the declared set." ## Operational Effect Operationally, teams that conflate the two surfaces ship loaders that pass every signature test and still execute injected code. The failure is silent in CI because the test artifact is benign; it surfaces only when a malicious artifact is published, and by then the trust boundary has already been crossed in production. The fix is structural, not detective: move rehydration into a confined child, seed the syscall filter from the declared capability set, and treat any syscall outside that set during materialization as a hard rejection — not a warning. The attestation then covers what it can actually promise (bytes and declared intent), and the sandbox covers what attestation cannot (evaluation semantics). The two together are sound; either alone is not. ```python import hashlib import pickle import subprocess class AttestationRehydrationError(RuntimeError): """Raised when a manifest is attested but rehydration escapes the declared capability set.""" pass ALLOWED_SYSCALLS = {"read", "write", "open", "close", "stat", "mmap", "brk"} def verify_manifest(manifest: dict, publisher_key: bytes) -> bool: body = manifest["body"].encode() expected = hashlib.sha256(body + publisher_key).hexdigest() return expected == manifest["digest"] def rehydrate_confined(artifact: bytes, declared_caps: set[str]) -> object: """ Materialize the artifact in a child process under a syscall filter seeded from declared_caps. Reject on any syscall outside the declared set. Never call pickle.load / yaml.load / torch.load in the loader's own space. """ # Non-evaluating path is the only in-process-safe path. if artifact[:1] == b"{": import json return json.loads(artifact.decode()) # Evaluating format: must be confined. Simulate the child result here. observed_syscalls = _run_confined_child(artifact) undeclared = observed_syscalls - declared_caps - ALLOWED_SYSCALLS if undeclared: raise AttestationRehydrationError( f"rehydration issued undeclared syscalls {sorted(undeclared)}; " f"declared={sorted(declared_caps)}" ) return _load_nonedata(artifact) def _run_confined_child(artifact: bytes) -> set[str]: # Placeholder: real implementation forks, applies seccomp, and traces syscalls. # A pickle __reduce__ payload would surface 'execve' or 'socket' here. return {"read", "write", "open", "execve"} def _load_nonedata(artifact: bytes) -> object: return pickle.loads(artifact) def load_skill(manifest: dict, artifact: bytes, publisher_key: bytes) -> object: if not verify_manifest(manifest, publisher_key): raise AttestationRehydrationError("manifest digest does not match publisher key") declared = set(manifest.get("capabilities", [])) return rehydrate_confined(artifact, declared) ```