How to Block Destructive Shell Commands from AI Agents (MCP Shell Safety)
Shell-capable MCP tools are the sharpest knife in the drawer. An agent that can run commands can fix your build, migrate your files, and manage your servers — and the same tool, one hallucination or one prompt injection later, can run the command that erases a disk. The infamous failure mode isn’t malice; it’s an agent confidently “cleaning up” with rm -rf on the wrong path, or a hijacked session told to wipe what it can reach.
Per-tool policies help (deny or approval-gate the shell tool), but sometimes you need the shell tool enabled and fast. For that case, MCP Trail has a dedicated guardrail: dangerous command blocking — argument-level inspection of shell-running tools that stops instructions which would erase data, wipe disks, or similarly harm systems, while letting ordinary commands through.
Why a separate control just for shell?
Because shell tools break the assumptions per-tool policy relies on. For most tools, the tool name tells you the risk (delete_repo is obviously dangerous). A shell tool is one name with unbounded behavior — run_command is harmless or catastrophic depending entirely on its arguments. So the guardrail has to look inside the call, not just at its name.
Step 1: Create your free MCP Trail account and add your server
Sign up at app.mcptrail.com and route your shell-capable server through the gateway — hosted from the marketplace or by fronting an existing URL.
Step 2: Turn on dangerous command blocking
Open the server under Guardian servers → Security tab → Access & shell. The Dangerous command blocking card is a single switch. Flip it on: from now on, tool calls whose arguments contain destructive shell patterns — data-erasing deletes, disk wipes, and similar system-harming instructions — are blocked at the gateway before they reach the server.

Step 3: Test it with a harmless probe
Ask your connected assistant to run something that matches the destructive shape without a real target — the block is decided at the gateway, so nothing executes. The call comes back with an explicit policy error, and the attempt is recorded.
Step 4: Check the audit trail
Open Audit log: the blocked call is there with the tool name and the policy decision. This is the record that turns “the agent tried something destructive once” from a scary anecdote into a reviewable event.

Step 5: Layer it
Shell safety is one layer, built for one failure mode. Pair it with:
- Human approval on the shell tool — blocking catches known-destructive shapes; approval catches everything else
- Session risk scoring with the shell tool weighted High — a session that leans on the shell repeatedly gets flagged even when each command looks fine
- Tool sequence rules — e.g. no shell before a required validation step
FAQ
Does this replace reviewing what my agent does?
No — it’s a floor, not a ceiling. It stops the catastrophic-and-obvious class instantly; judgment calls still belong in the approval queue.
Will it block legitimate cleanup commands?
The patterns target system-harming operations (data erasure, disk wipes). Ordinary file management passes. If your workflow genuinely requires destructive commands, route that tool through human approval instead and keep blocking on for everything else.
Does it work on any MCP server?
It applies to tools that run shell commands on servers routed through the gateway — regardless of where the server itself is hosted.
What does the agent see when a command is blocked?
An explicit policy error it can relay to the user — not a silent failure it might retry around.
Related Articles
- Threat: Destructive Shell & Filesystem Access via MCP
- How to Control Which MCP Tools Your AI Can Run
- MCP Session Risk Scoring
- MCP Approvals: Human-in-the-Loop for AI Tool Calls
- How MCP Trail Guardian Maps MCP Threats to Real Controls
One toggle between your agent and the worst command it will ever hallucinate. Create your free MCP Trail account and switch it on.