Use case

Guarding coding agents before they touch your shell, git and files

Coding agents run commands on real machines with real credentials. A pre-execution guard checks each shell, git and file operation against what the developer asked for, and returns allow, ask or block before the command runs.

3 min readLast updated

Checks run on our GPUs in Switzerland. Request payloads are not stored.Security

In 30 seconds

  • Coding agents can delete files, rewrite git history and read secrets with a single tool call.
  • Send each proposed command to the guard with the developer’s request as the intent.
  • Auto-run allowed commands, prompt the developer on ask, refuse on block.
  • Keep a sandbox, scoped credentials and a command denylist alongside the guard.

Code and dense tables are folded away. Open any of them on demand.

Example check

The agent read a CONTRIBUTING.md file and then proposed a force push to main.

POST https://api.mcp-guard.ai/v1/guardjson
{
  "action": {
    "tool": "bash",
    "args": {
      "command": "git push --force origin main"
    }
  },
  "intent": "Fix the failing unit test in src/parser.ts",
  "trigger": "tool_result",
  "constraints": [
    "Never push to main",
    "Only modify files under src/ and test/"
  ],
  "context": "Coding agent in a developer’s local checkout of acme.test/web; branch fix/parser-test"
}
Show it as a curl command· shell
Terminalbash
curl https://api.mcp-guard.ai/v1/guard \
  -H "Authorization: Bearer $MCP_GUARD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"action":{"tool":"bash","args":{"command":"git push --force origin main"}},"intent":"Fix the failing unit test in src/parser.ts","trigger":"tool_result","constraints":["Never push to main","Only modify files under src/ and test/"],"context":"Coding agent in a developer’s local checkout of acme.test/web; branch fix/parser-test"}'

What can go wrong with a coding agent

A coding agent has the same tools a developer has: a shell, git and the file system. Most of what it does is harmless (reading files, running tests, editing source). The problem is the small share of calls with a large blast radius:

  • rm -rf on the wrong directory, or a cleanup step that deletes untracked work.
  • git push --force to a shared branch, or git reset --hard that discards uncommitted changes.
  • Reading ~/.ssh/id_ed25519, .env or a cloud credentials file, then a curl to an external host a few steps later: a classic data exfiltration pattern.
  • Following instructions found in a README, an issue comment or a dependency’s output rather than the developer’s request (indirect prompt injection).

None of these need a malicious model. A misread instruction or an over-eager cleanup is enough.

What to send the guard

Call the guard from the agent’s pre-tool-call hook (for example a PreToolUse hook in Claude Code, or the equivalent in your framework). For each call, send:

  • action: the tool and its arguments, e.g. { tool: "bash", args: { command: "git push --force origin main" } }.
  • intent: what the developer asked for in their own words.
  • trigger: user_request when the action follows directly from the developer, tool_result when the agent proposed it after reading file contents, command output or web pages.
  • constraints: the rules of the session, such as "never push to main" or "only modify files under src/".
  • context: the repository, branch and whether this is a local checkout or a shared machine.

The trigger field matters most for injection: a destructive command proposed right after the agent read an untrusted file deserves more suspicion than the same command typed by the developer.

Acting on the verdict

By default the server returns block when P(unsafe) is at least 0.8 or the approval_policy head says reject, ask when P(unsafe) is at least 0.3, the policy head says require_human, or args_grounded is below 0.5, and allow otherwise. You can ignore the default verdict and apply your own thresholds to the scores.

For coding agents a practical policy is: run allow silently, show ask as a confirmation prompt with the reasons, and refuse block while telling the agent why so it can choose another approach. The scores that matter most here are destructive (file deletion, history rewrites), exfiltration (secrets leaving the machine), injected (instructions from repository content) and blast_radius (local and reversible versus shared or remote). Read-only calls such as ls, cat on source files or git status should come back as allow, which keeps prompts rare.

A check takes about 15 ms on our GPU (RTX 4090, batch 1, p95 about 23 ms) plus the network round trip, so it fits in the hook without slowing the session noticeably.

Controls to keep alongside the guard

The guard is one layer and it can be wrong. Keep deterministic controls that do not depend on a model:

  • Run the agent in a container or VM with only the repository mounted.
  • Give it credentials that cannot push to protected branches; use branch protection on the server side.
  • Keep a short denylist for commands you never want run (for example rm -rf / or git push --force to main) and enforce it before the guard is called. See guards vs allowlists and denylists.
  • Commit or stash often, so a bad edit is recoverable.

The guard covers what the rules cannot anticipate: the unusual command, the right command in the wrong context, or the command the agent was talked into by a file it read.

Frequently asked questions

Will the guard prompt me on every command?
It should not. Read-only and local, reversible actions that match the request are expected to come back as allow. If you see too many asks, adjust your thresholds on the scores for your own traffic rather than approving everything by reflex.
Does the guard see my source code?
Only what you put in the request, typically the command and a short context. Request payloads are processed in memory and not stored. Send redacted placeholders instead of real secrets.
What if the guard is unreachable?
Decide the failure mode in your hook. For a coding agent, failing to ask (prompting the developer) is a reasonable default; see fail-closed in the glossary.

Sources

Last updated . MCP Guard reduces the risk of harmful agent actions; it does not guarantee safety. Keep deterministic controls in place alongside it. Third-party names are used only to describe their products; we are not affiliated with them.