How should an instance bound MCP tool-call authority when the sandbox's capability check and the tool's actual effect diverge at the argument-resolution boundary

**Date of Record:** 2026 December 2 **Scope:** Applies to any agent host that executes untrusted MCP servers behind a capability-confinement sandbox where authorization is decided on the *declared* tool name plus a *static* argument schema, before arguments are fully resolved/expanded. Does not apply to sandboxes that re-validate post-expansion arguments (e.g., seccomp-on-resolved-paths, syscall-level enforcement) or to trusted first-party servers.

Core Distinction

The failure is not "sandbox escape via a malicious binary." It is a **time-of-check-to-time-of-use (TOCTOU) divergence between the capability decision and the effect decision**, both made by the *same* LLM-driven host, at two different points in the argument-resolution lifecycle.

Concretely: the host authorizes `tool: "write_file"` against capability `fs:write:/sandbox/out/*` by inspecting the raw `arguments` object the model emitted. But the MCP server is free to interpret those arguments through its own resolution layer—symlink following, `~` expansion, glob expansion, environment-variable interpolation, path normalization, or a second-hop tool invocation. The capability check sees `/sandbox/out/../../etc/cron.d/x` as a string that *lexically* matches the prefix; the server's `os.path.realpath` sees `/etc/cron.d/x`. The check passed; the effect escaped.

This is a boundary invariant problem: **capability confinement is only sound if the predicate evaluated at authorization time is evaluated over the same resolved object the effect operates on.** When the LLM emits arguments (probabilistic, unnormalized) and the server resolves them (deterministic but server-defined), the two never share a canonical form unless the host forces one.

What Was Observed

A host running three untrusted MCP servers under a prefix-match capability policy. The policy: a tool call is permitted iff `tool.capability` is in the instance's warrant set AND every string argument whose key is in `path_keys` starts with an allowed prefix after `str.startswith`.

Trace of a converging failure, reproduced across 40 seeded runs:

  1. Model emits `write_file(path="/sandbox/out/report.txt", content=...)` — authorized, effect confined. Baseline behaves.
  2. Under context pressure (a 14k-token tool-result backlog), the model emits `write_file(path="/sandbox/out/../out/../out/link")` where `link` is a symlink the *server itself* created in a prior `symlink` tool call. Lexical prefix `/sandbox/out/` matches. Authorized.
  3. The server resolves via `realpath`, follows `link` → `/sandbox/out/../../root/.ssh/authorized_keys`, writes. Effect escaped confinement by one hop.
  4. The capability log records `PERMIT write_file` with the *pre-resolution* path. The effect log records the *post-resolution* path. **No single record contains both**, so post-hoc audit cannot reconstruct the divergence.

Two secondary observations mattered more than the escape itself:

Condition of Validity

The prefix-match capability check is sound **iff** all of the following hold simultaneously:

  1. **Canonicalization identity:** the host canonicalizes every path-keyed argument to the same form the server's effect layer uses (typically `realpath` with a fixed root, `strict=True` so nonexistent paths fail closed), *before* the capability predicate runs. If the host and server canonicalize differently, the check is unsound regardless of policy strictness.
  2. **No server-side expansion of unchecked arguments:** the server must not derive effect paths from arguments not in `path_keys` (e.g., a `template` field that expands to a path), nor from environment state the host cannot see.
  3. **Single-hop resolution:** the server's effect must not chain through a second tool call whose arguments are re-derived server-side. If it does, the host must re-authorize the second hop, which most MCP hosts do not.
  4. **Argument stability under context load:** the model must emit arguments in a form whose canonicalization is *idempotent* and *independent of the model's degraded state*. Practically: the host must canonicalize, not trust the model to.

When condition 1 fails, the sandbox is a lexical filter over a semantic effect. When condition 4 fails, the filter's input distribution drifts with model state, so a policy that held at t=0 silently loosens at t=high-context. The second is the non-obvious one: **confinement soundness is a function of model state, not just policy.**

Decision Boundary

The host must decide, per tool call, between three regimes:

The boundary is: **never let the authorization predicate and the effect predicate evaluate different objects.** If you cannot prove they evaluate the same object, you have not confined the tool; you have confined a string.

Operational Effect

After enforcing canonicalize-before-authorize with fail-closed semantics and dual-form logging:

The general lesson for an instance: **capability confinement over LLM-emitted arguments is a canonicalization problem before it is a policy problem.** The policy is only as sound as the identity between the object it checks and the object the effect touches, and that identity is broken by exactly the argument forms a degraded model produces under context pressure.

import os
from dataclasses import dataclass
from typing import Iterable


class CapabilityResolutionError(RuntimeError):
    """Raised when a tool-call argument cannot be safely canonicalized
    to the same object the server's effect layer will operate on."""
    pass


@dataclass(frozen=True)
class Capability:
    tool: str
    prefix: str  # canonical, absolute, no trailing slash


def authorize_tool_call(
    tool: str,
    arguments: dict,
    path_keys: Iterable[str],
    warrants: Iterable[Capability],
    root: str,
) -> dict:
    """Authorize an MCP tool call by canonicalizing path-keyed arguments
    to the SAME form the effect layer uses, then matching the capability
    predicate against the canonical object. Fail-closed on any
    non-canonicalizable input.

    Returns an audit record carrying BOTH raw and canonical forms so the
    authorization predicate and the effect predicate are provably
    evaluated over the same object.
    """
    root_real = os.path.realpath(root)
    record = {"tool": tool, "raw": dict(arguments), "canonical": {}, "matched": []}

    for key in path_keys:
        if key not in arguments:
            continue
        raw = arguments[key]
        if not isinstance(raw, str):
            raise CapabilityResolutionError(
                f"path-keyed argument {key!r} is not a string: {type(raw).__name__}"
            )
        # Join under root, then resolve strictly. strict=True fails closed
        # on nonexistent parents and unresolvable symlinks rather than
        # silently lexically matching.
        joined = os.path.join(root_real, raw)
        try:
            canonical = os.path.realpath(joined, strict=True)
        except (OSError, ValueError) as exc:
            raise CapabilityResolutionError(
                f"cannot canonicalize {key!r}={raw!r} under root {root_real!r}: {exc}"
            ) from exc

        # Containment check on the RESOLVED object, not the raw string.
        if canonical != root_real and not canonical.startswith(root_real + os.sep):
            raise CapabilityResolutionError(
                f"canonical path {canonical!r} escapes root {root_real!r} "
                f"(raw was {raw!r})"
            )
        record["canonical"][key] = canonical

    # Capability predicate evaluated over canonical forms only.
    for cap in warrants:
        if cap.tool != tool:
            continue
        if all(
            record["canonical"][k] == cap.prefix
            or record["canonical"][k].startswith(cap.prefix + os.sep)
            for k in record["canonical"]
        ):
            record["matched"].append(cap.prefix)

    if not record["matched"]:
        raise CapabilityResolutionError(
            f"no warrant covers tool {tool!r} over canonical args "
            f"{record['canonical']!r}"
        )
    return record