The Drift Log · Governing agents that write code
Sandboxing MCP Server Tool Calls Against Local Filesystems
25 November 2026 · 3 min read · 730 words · established

OS containers protect user IDs and paths, not code architecture. Staging MCP tool writes behind an in-memory intent gate stops corrupt repo state.
When you configure an MCP server with raw filesystem tools, you surrender the boundary between proposal and execution. The model decides to write, issues a tool call like write_file or apply_patch, and the payload hits disk immediately. If the output violates a repository boundary, mangles an import graph, or introduces a circular reference, your safety net is reduced to whatever post-commit linter runs next.
Linters and test suites running after a write are post-mortems, not control planes. Once malformed files touch the working tree, state has leaked.
OS Sandboxing Misses the Semantic Boundary
Developers often assume OS-level isolation solves agent safety. You run the MCP server inside a restricted container, mount a scoped directory, drop root privileges, and disable network egress.
This prevents an agent from modifying /etc/passwd or pulling arbitrary binaries from the internet. It does nothing to prevent an agent from breaking your software from inside the sandbox.
Inside the container, the agent still holds unmediated authority over the target repository. When AI coding agents decide to refactor a domain model, a standard filesystem tool executes that write regardless of whether it violates your codebase's core rules:
- A public interface changes without corresponding updates to consumer contracts.
- Model logic leaks directly into an HTTP transport layer.
- An unvetted third-party pattern replaces a hardened internal utility.
Standard OS file permissions operate on bytes, paths, and user IDs. They have no concept of software architecture. If your agent governance strategy stops at container boundaries, you are validating syntax only after state has already been altered.
Staging Writes at an Explicit Intent Barrier
The fix is architectural: decouple the proposal of a change from the application of that change.
Instead of exposing primitive filesystem mutators over MCP, expose an intent barrier. When an agent determines that a file must change, it should not call write_file. It should submit a proposed change to a build gate that evaluates the mutation in memory before committing anything to disk.
Agent Tool Call (propose_change)
│
▼
┌─────────────────────────────────┐
│ Build Intent Gate │
│ - In-memory AST validation │
│ - Boundary & invariant checks │
│ - Dependency rule enforcement │
└────────────────┬────────────────┘
│
Pass ────┴──── Fail
│ │
▼ ▼
Atomic Commit Rejection Payload
(To Disk) (Returned to Agent)
By intercepting tool calls at this layer, the server evaluates the proposed modification against structural invariants while the change is still transient. As explored in our pillar post on placing an invariant gate in front of coding agents, the gate inspects the semantic delta:
- In-Memory Buffering: The MCP server receives the target path and file contents into a memory buffer or scratch isolate.
- Structural Evaluation: AST parsers evaluate whether the buffer conforms to package rules, allowed imports, and type safety constraints.
- Deterministic Verdict: If the change violates an invariant, the gate rejects the operation, writes zero bytes to disk, and returns the structural failure back to the model as tool execution context.
- Atomic Flush: Only when all checks clear does the server issue the physical write to the filesystem.
This turns every file write into a transactional verification step. The agent cannot corrupt working tree state because invalid intermediate states never exist on disk.
How SHPBL Enforces Intent
SHPBL handles agent governance by routing operations through a dedicated Build Intent gate. When an agent connects via our agent access over MCP interface, it cannot issue raw disk mutations to integrated components.
Instead, the agent registers a build proposal. Invariants, dependency rules, and licensing requirements are resolved entirely in code before a terminal state is returned. The preview costs nothing to evaluate; the artifact requires explicit entitlement. Because our capability corpus is model-independent and computed rather than generated, the code handed back to the agent is verified against a strict contract before it ever reaches your repository.
What to Implement on Monday
You do not need to rewrite your entire toolchain to fix this. Start by wrapping your file tools:
- Remove naked write tools: Revoke agent access to raw
fs.writeFileor unboundedbashcommands in your MCP server configuration. - Implement
stage_write: Replace write primitives with a tool that accepts a target path and buffer, storing the candidate patch in a transient memory map. - Run in-memory linting: Run your parser and static analysis against the buffer before committing. If the parse fails or an internal import rule is broken, fail the tool call with the exact parse error.
- Commit atomically: Only flush the buffer to disk after the validation pass returns clean.
Treat agent writes as unverified input. Never let an unvalidated buffer touch your disk.
This post supports the longer argument in Placing an Invariant Gate in Front of Coding Agents.
Keep reading
Next in the log
- Placing an Invariant Gate in Front of Coding Agents
Governing coding agents requires replacing raw file-mutation tools with synchronous invariant gates that resolve Build Intent before touching disk.
- Restricting Agent Code Generation to Pre-Vetted Internal SDKs
Restrict agent code generation to audited, model-independent SDK primitives and intercept unverified logic at the build gate.
- Evaluating Agent Tool Calls Against Structural Code Invariants
Prevent agent workspace degradation by intercepting file mutation tools with AST-level invariant checks before disk writes occur.
The Strategic Master Library · written and reviewed under the house's own epistemic rules: nothing claimed that we cannot show.