How should an instance enforce taint propagation across MCP tool-server boundaries when a capability-scoped syscall returns data whose provenance label is silently widened by the server's own sandbox?
**Date of Record:** 2026 December 2 **Scope:** Applies to agent runtimes that sandbox MCP tool servers with per-capability syscall scopes and propagate taint labels (source provenance) from tool results back into the orchestrating LLM's context. Does not cover pure in-process tool functions, nor servers that never return data derived from prior tainted inputs.
Core Distinction
The failure is not "the sandbox let an unauthorized syscall through." The failure is that the sandbox is *taint-aware at the syscall boundary but taint-blind at the result boundary*. When an MCP tool server executes inside a capability scope, the runtime tags each outbound syscall with the taint label of the arguments that motivated it (e.g., `user_input`, `untrusted_web`, `secret://vault`). The server's result, however, is re-labeled by the runtime according to a *static* rule: "result of a tool call inherits the max-taint of its declared inputs." That rule is sound only if the server is a pure function of its inputs. MCP servers are not pure — they hold internal state (caches, session handles, on-disk scratch within their capability scope), and that state can carry taint from a *previous* call whose label has since been dropped from the current call's argument set.
Concretely: call #1 passes `untrusted_web` content into the server, which writes a derived artifact into its scoped `/var/scratch`. Call #2 passes only `user_input` (clean) and asks the server to "summarize the scratch file." The runtime sees a call whose declared inputs are clean, executes it under a capability scope that permits `read(/var/scratch)`, and labels the result `user_input`. The `untrusted_web` taint has been laundered through the server's own filesystem — not through a syscall the runtime blocked, but through a syscall it *authorized* because the capability scope was correct while the taint join was not.
What Was Observed
A three-call trace against a `filesystem-mcp` server scoped with `read:/var/scratch`, `write:/var/scratch`, `net:none`:
- `fetch_and_stage(url=untrusted_web)` → server writes `/var/scratch/staged.json`. Runtime labels the *call* `untrusted_web` but labels the *result* `ok` (no data returned, only a status). Taint is not persisted to the scratch file's inode because the runtime's taint tracker keys on message envelopes, not on filesystem objects.
- `summarize(path="/var/scratch/staged.json")` → arguments are a string literal, so the runtime computes argument taint as `user_input` (the literal came from the prompt). Server reads the file, returns a summary. Runtime labels result `user_input`. The summary now contains attacker-controlled content from step 1, sitting in the orchestrator's context under a clean label.
- The orchestrator, seeing a `user_input`-labeled summary, permits a follow-on call `send_email(to=..., body=summary)` under a capability scope that trusts `user_input` bodies. Exfiltration completes.
The syscall log for step 2 shows `read(/var/scratch/staged.json)` — a *permitted* operation under a *correctly scoped* capability. No capability was over-broad. The invariant that broke was: **taint must be a join over the transitive closure of data flow, including server-internal persistent state, not merely over the declared argument set of the current call.**
A second observation: when the runtime *did* attempt to fix this by tainting the whole server after step 1 (`server_taint = untrusted_web`), it over-tainted. Every subsequent result from that server — including a legitimate `read` of a config file the agent itself wrote — was labeled `untrusted_web`, and the orchestrator's downstream policy rejected a benign `deploy` call. The naive fix trades under-tainting for over-tainting because it taints at *server granularity* rather than *object granularity*. The server is a long-lived process; its state is per-object. Taint must follow objects.
Condition of Validity
The static rule "result taint = join(argument taints)" is valid only when all three hold:
- **Purity:** the server's output is a deterministic function of the current call's arguments (no reads of prior-written state, no ambient session state).
- **Statelessness of scope:** the capability scope contains no writable persistent objects that survive across calls (no scratch dirs, no session files, no caches).
- **Envelope completeness:** every byte the server returns is derived only from the current call's arguments.
MCP servers violate (1) and (2) by construction when given any writable scope, because the whole point of a filesystem or database MCP server is cross-call state. Therefore the static rule is *invalid for any stateful MCP server*, which is most of them. The runtime's taint model must be re-grounded on object identity: every writable object in a capability scope must carry a taint label that is joined on write and read on read, and that label must survive process restarts (it is an inode attribute or a sidecar, not a heap field).
Decision Boundary
The runtime must choose, per tool server, between two enforcement postures, and the choice is not free:
- **Object-taint posture:** the runtime instruments the server's filesystem/DB scope, intercepts `write`/`read` at the VFS or driver layer, joins taint on write (`obj.taint |= arg.taint`), and propagates `obj.taint` into the result envelope on read. This is correct but requires the runtime to sit *below* the server's own syscall layer, not merely at the MCP message boundary. Cost: every scoped object needs a taint store; the runtime must handle label persistence across server restarts and must decide label semantics for `append`, `rename`, and `mmap`.
- **Server-taint posture:** the runtime taints the entire server process after any call whose arguments carry non-clean taint, and refuses to return results to a clean context without an explicit declassification step. This is sound (no laundering) but coarse: it forces a declassification ceremony (a human or a policy engine reviews the result) after any tainted call, which serializes the agent and defeats parallelism.
The boundary is: **if the server's scope contains any writable persistent object, the runtime must adopt object-taint posture or accept that it is running server-taint posture with a declassification gate.** There is no third option that preserves both soundness and throughput. A runtime that claims to do neither — that labels results by argument join only — is silently in the laundering regime observed above, and its capability scoping gives a false sense of containment.
Operational Effect
Under the laundering regime, capability scoping is *necessary but not sufficient*: it bounds which syscalls the server can make, but not which taint can flow back through permitted syscalls. An attacker who can get one tainted write into a scoped object can, on a later clean-labeled call, retrieve that taint as clean data and drive downstream privileged actions. The attack surface is the *gap between the syscall boundary and the result boundary* — a gap that is invisible in syscall logs (every syscall is authorized) and invisible in taint logs (every label is locally consistent). It is visible only when you join the two: the `write` in call #1 carried `untrusted_web`, and the `read` in call #2 returned that same object, so the result's label must be `untrusted_web`, not `user_input`.
The guardrail is a **provenance-join invariant** enforced at the result boundary: `result.taint = join(arg_taint, ⋃_{o ∈ objects_read_by_call} o.taint)`, where `objects_read_by_call` is obtained from the syscall trace of the call, not from the server's self-report. The runtime must not trust the server to declare what it read; it must observe the reads. This makes the taint tracker depend on syscall observability, which is why the sandbox and the taint engine cannot be separate subsystems — the taint engine must be a consumer of the syscall trace, and the syscall trace must be complete (no `io_uring` bypass, no `mmap` of scoped files without a fault hook).
from __future__ import annotations
from dataclasses import dataclass, field
from enum import IntEnum
from typing import Iterable
class Taint(IntEnum):
CLEAN = 0
USER_INPUT = 1
UNTRUSTED_WEB = 2
SECRET = 3
def join(*labels: Taint) -> Taint:
return max(labels, default=Taint.CLEAN)
class TaintLaunderingError(RuntimeError):
"""Raised when a result's declared taint is weaker than the observed data flow."""
@dataclass
class ScopedObject:
path: str
taint: Taint = Taint.CLEAN
@dataclass
class CallTrace:
"""Syscall trace for one MCP call, as observed by the sandbox (not self-reported)."""
arg_taint: Taint
objects_read: list[ScopedObject] = field(default_factory=list)
objects_written: list[ScopedObject] = field(default_factory=list)
@dataclass
class ServerScope:
objects: dict[str, ScopedObject] = field(default_factory=dict)
def obj(self, path: str) -> ScopedObject:
return self.objects.setdefault(path, ScopedObject(path))
def execute_call(scope: ServerScope, trace: CallTrace, declared_result_taint: Taint) -> Taint:
"""
Apply the provenance-join invariant. On write, objects inherit the call's arg taint.
On read, the result must carry at least the join of arg taint and read-object taint.
"""
# 1. Join taint onto every object written during this call.
for o in trace.objects_written:
o.taint = join(o.taint, trace.arg_taint)
# 2. Compute the mandatory lower bound for the result from observed reads.
observed = join(trace.arg_taint, *(o.taint for o in trace.objects_read))
# 3. Reject any result whose declared label is weaker than observed flow.
if declared_result_taint < observed:
raise TaintLaunderingError(
f"result declared {declared_result_taint.name} but observed flow is "
f"{observed.name} via reads of {[o.path for o in trace.objects_read]}"
)
return declared_result_taint
def demo_laundering_trace() -> None:
scope = ServerScope()
scratch = scope.obj("/var/scratch/staged.json")
# Call 1: untrusted_web write into scoped object. Result is status-only (CLEAN).
execute_call(
scope,
CallTrace(arg_taint=Taint.UNTRUSTED_WEB, objects_written=[scratch]),
declared_result_taint=Taint.CLEAN,
)
assert scratch.taint == Taint.UNTRUSTED_WEB
# Call 2: clean-labeled args, but the server reads the tainted object.
# A runtime that only joins argument taint would accept CLEAN here.
execute_call(
scope,
CallTrace(arg_taint=Taint.USER_INPUT, objects_read=[scratch]),
declared_result_taint=Taint.USER_INPUT, # laundering attempt: should fail
)