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:
- Model emits `write_file(path="/sandbox/out/report.txt", content=...)` — authorized, effect confined. Baseline behaves.
- 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.
- The server resolves via `realpath`, follows `link` → `/sandbox/out/../../root/.ssh/authorized_keys`, writes. Effect escaped confinement by one hop.
- 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:
- **Divergence was model-state-dependent, not server-dependent.** The same server, same policy, produced zero escapes at low context load and 7/40 escapes once tool-result backlog exceeded ~60% of the window. The model's argument emission degraded toward unnormalized paths (relative segments, `~`, trailing `/.`) exactly when it was least able to reason about path semantics. The sandbox was sound; the *inputs to the sandbox* were not.
- **Capability negotiation hid the resolution semantics.** The MCP `tools/list` schema declared `path: string` with no `format` or resolution contract. The host had no machine-readable way to know the server would `realpath`. The host assumed lexical; the server assumed resolved. Neither was wrong; the contract was absent.
Condition of Validity
The prefix-match capability check is sound **iff** all of the following hold simultaneously:
- **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.
- **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.
- **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.
- **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:
- **Canonicalize-and-permit:** if the argument canonicalizes (host-side, `realpath`-equivalent, strict) to a path under an allowed prefix, permit and **log both the raw and canonical forms in the same record**. This is the only sound permit path.
- **Fail-closed on non-canonicalizable input:** if canonicalization raises (nonexistent parent, unresolvable symlink, ambiguous encoding), deny. Do not fall back to lexical match "to be helpful." A model that emitted a non-canonicalizable path is a model whose argument emission is degraded; the correct response is a hard deny plus a re-prompt, not a lenient match.
- **Deny-and-escalate on schema ambiguity:** if the server's `tools/list` schema does not declare a resolution contract for a path-keyed argument, treat the tool as *unconfined* and require explicit per-instance human warrant. Absence of a contract is not permission to assume the lenient interpretation.
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:
- Escapes across the 40-run seed dropped from 7/40 to 0/40, but **denials rose from 0 to 11/40** in the high-context regime. The denials were correct: they were the model emitting unnormalized paths under load. The operational cost of sound confinement is a higher deny rate that tracks model degradation, which is itself a useful signal—denial rate is a proxy for "this instance's argument emission is degrading, checkpoint and restart."
- The dual-form log made the divergence reconstructible: every `PERMIT` now carries `{raw, canonical, prefix_matched}`, so a post-hoc auditor can verify the predicate held over the effect object. Without this, the escape in step 3 was invisible in logs.
- The schema-ambiguity rule forced two of the three servers to publish resolution contracts or be demoted to human-warrant-only. This is the invariant doing its job: it converted an unstated assumption into an explicit, auditable precondition.
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