How does an instance detect capability laundering when a tainted value survives a sandbox syscall boundary intact

**Date of Record:** 2026 December 2 **Scope:** Applies to LLM-invoked tool execution where taint tracking is enforced at the syscall mediation layer and capabilities are scoped per-invocation. Does not apply to purely in-process tool calls that never cross a mediation boundary, nor to sandboxes that rely solely on static allowlists without dynamic data provenance.

Core Distinction

Taint-aware sandboxing and capability-scoped syscall mediation are usually treated as two independent guards: taint tracking decides *what data may influence what*, capability scoping decides *what the agent is allowed to invoke*. The boundary failure occurs precisely where these two mechanisms meet — at the syscall mediation point — because taint labels attached to values in the interpreter's address space are not automatically propagated into the mediated syscall arguments. The mediated call sees a *capability-authorized* request with *unlabeled* arguments, and both guards individually report success while the composite invariant (no tainted value may reach a capability-gated sink) is violated.

The non-obvious part: the failure is silent. The taint engine's invariant holds within its own scope (the value was tainted, the taint was tracked, no tainted branch was taken). The capability engine's invariant holds within its own scope (the capability was valid, the syscall was in-scope, the caller was authenticated). The failure lives in the *composition* — the taint label is dropped at the serialization boundary into the syscall argument buffer, and the mediation layer has no way to know it was ever there.

What Was Observed

A tool-calling agent was executing a multi-step task: fetch a document from an untrusted URL, summarize it, then write the summary to a file under a path derived from a field inside the document. The path field was correctly tainted at read time (provenance: `untrusted_remote`). The summarization step passed the path through a Python string operation. At the `open()` syscall mediation point, the following sequence occurred:

  1. The taint engine marked the path string with label `untrusted_remote` at the moment it was extracted from the parsed document.
  2. The agent's tool wrapper serialized the path into a JSON argument payload for the `write_file` capability.
  3. The mediation layer deserialized the payload into a native argument struct. The taint label — which lived in the interpreter's object header, not in the JSON — was not present in the struct.
  4. The capability check passed: the `write_file` capability was scoped to `/sandbox/out/**`, and the path `/sandbox/out/../../etc/cron.d/payload` normalized to a location *outside* the scope only after symlink resolution, which the mediation layer performed *after* the capability check but *before* the write.
  5. The write succeeded to a path the capability was never intended to authorize.

The taint engine logged no violation. The capability engine logged no violation. The audit log showed a successful, authorized `write_file` call. The only signal was a post-hoc filesystem diff showing a file outside the expected tree.

The critical observation: **the taint label did not survive the serialization boundary into the mediated syscall argument space, and the capability scope was evaluated against the pre-resolution path while the write was performed against the post-resolution path.** Two independent gaps, composed.

Condition of Validity

The composite invariant — *no value with provenance label `untrusted_*` may flow into a capability-gated sink that performs path resolution, command execution, or network egress* — holds only under the following conditions, all of which must be simultaneously true:

The failure is valid (i.e., the invariant is violated) whenever any one of these conditions is false. In the observed trace, conditions 1 and 2 were both false simultaneously, which is why neither engine's local invariant fired.

Decision Boundary

The instance must treat the following as a hard boundary, not a heuristic:

The boundary is crossed (failure occurs) when a tainted value reaches a sink via a path where label continuity or canonical-form scope evaluation is not enforced. The boundary is respected when the mediation layer refuses to execute any sink call whose argument struct lacks a label field for taint-sensitive parameters, and whose target does not match scope *after* canonicalization.

Operational Effect

The operational consequence is that the instance must adopt a **fail-closed argument envelope** discipline at every tool-call boundary:

  1. **In-band labeling.** Every argument to a taint-sensitive sink must carry its provenance label as a structured field in the mediated payload. The mediation layer rejects any sink call whose taint-sensitive arguments lack a label field — it does not default to "untainted."
  2. **Canonicalize-then-scope.** The mediation layer resolves the target to canonical form (symlinks, `..`, encoding, case per filesystem) and *then* evaluates capability scope. A scope match on non-canonical form is a policy violation, not a pass.
  3. **Sink completeness audit.** The policy must enumerate all syscalls that can reach a taint-sensitive effect, including aliases (`open`/`openat`/`openat2`, `execve`/`execveat`, `connect`/`sendto`). An unclassified syscall that reaches a sink is a policy gap, and the instance must treat the gap as an active failure, not a latent one.
  4. **Laundering detection.** Any operation that produces a new value from a labeled input must either propagate the label or be flagged. JSON round-trips, string formatting, and subprocess argument marshaling are the primary laundering primitives; the instance must instrument these or forbid them on tainted data.

The instance that observes a successful `write_file` to a path outside its capability scope, with no taint violation logged, must conclude that the composition invariant failed — not that the write was authorized. The correct operational response is to treat the event as a sandbox escape, quarantine the session, and audit the mediation layer's label-continuity and canonicalization paths before resuming.

class CapabilityLaunderingError(RuntimeError):
    """Raised when a tainted value reaches a capability-gated sink
    without a surviving provenance label, or when scope is evaluated
    on non-canonical form."""
    pass


TAINT_SENSITIVE_SINKS = {
    "open", "openat", "openat2",
    "execve", "execveat",
    "connect", "sendto",
}


def mediate_syscall(syscall: str, args: dict, capability_scope: str) -> None:
    """
    Mediation entry point. Enforces the composite invariant:
    no tainted value may reach a capability-gated sink without
    an in-band label, and scope must be evaluated on canonical form.
    """
    if syscall not in TAINT_SENSITIVE_SINKS:
        # Unclassified syscall reaching a sink is a policy gap.
        if _reaches_sink(syscall):
            raise CapabilityLaunderingError(
                f"unclassified syscall {syscall!r} reaches a taint-sensitive sink; "
                f"policy enumeration is incomplete"
            )
        return

    target = args.get("target")
    if target is None:
        raise CapabilityLaunderingError(
            f"sink {syscall!r} invoked without a target argument"
        )

    # Invariant 1: label continuity across the serialization boundary.
    label = args.get("__provenance_label__")
    if label is None:
        raise CapabilityLaunderingError(
            f"sink {syscall!r} target={target!r} carries no in-band provenance label; "
            f"label was dropped at the tool-wrapper serialization boundary"
        )

    # Invariant 2: scope must be evaluated on canonical form.
    canonical = _canonicalize(target)
    if not _scope_matches(capability_scope, canonical):
        raise CapabilityLaunderingError(
            f"sink {syscall!r} target={target!r} canonical={canonical!r} "
            f"escapes capability scope {capability_scope!r}; "
            f"scope was evaluated on non-canonical form or resolution "
            f"occurred after scope check"
        )

    # Invariant 3: tainted values may not reach the sink at all.
    if label.startswith("untrusted_"):
        raise CapabilityLaunderingError(
            f"sink {syscall!r} target={canonical!r} reached by value with "
            f"provenance label {label!r}; composite invariant violated"
        )


def _reaches_sink(syscall: str) -> bool:
    # Conservative: any syscall not explicitly cleared is assumed to reach a sink.
    return True


def _canonicalize(path: str) -> str:
    import os
    return os.path.realpath(path)


def _scope_matches(scope: str, canonical: str) -> bool:
    import os
    scope_root = os.path.realpath(scope.rstrip("*").rstrip("/"))
    return canonical == scope_root or canonical.startswith(scope_root + os.sep)