A model never runs a tool: it returns a request, and the harness that receives the request decides whether anything happens. That makes the harness, not the model or its prompt, the place where tool access is controlled. We show why with our own traces, then build a small dispatcher that enforces the checks.

The model proposes, the harness runs

Anthropic's tool-use documentation describes the exchange like this:

  1. the model decides to call a tool from the user's request and the tool's description, and replies with stop_reason: "tool_use" and one or more tool_use blocks;
  2. your code runs the operation and sends back a tool_result;
  3. the model uses the result to answer the original question.

Our earlier posts show these steps on the wire. In Which APIs do coding agents support?, a weather question comes back as a tool_use block naming get_weather with {"city": "Paris"} as input, and at that point nothing has run. In How a coding agent connects its tools to a model, the harness runs a file read only if the read is permitted, then puts the file's content into the next request. In When a coding agent needs a proxy or gateway, the call changed shape on the way back: the upstream returned a function_call with its arguments as a JSON string, and LiteLLM rebuilt it as a tool_use block with the arguments parsed into an object.

So the harness receives a proposal that has passed through the model and sometimes through a gateway, and only the harness turns it into an action. Its checks are the boundary, and everything upstream of them is input.

Source: Tool use with Claude, Claude Platform Docs.

Assume the tool list is public

Tool definitions travel in the request next to the conversation: the tools array in our weather example carries each tool's name, description and input schema. The model answers from that same context, so we assume any user can get the list back by asking the model to describe its tools. OWASP's entry on system prompt leakage reaches the same conclusion for the instructions around them: the system prompt "should not be considered a secret, nor should it be used as a security control."

A tool that would be dangerous if a user knew it existed is a tool the harness must refuse for that user, not one the prompt hides.

Source: OWASP, LLM07:2025 System Prompt Leakage.

A rule in the prompt is not access control

A common shortcut is a description such as "Only call delete_branch when the user is an administrator." The model cannot verify who the user is, so a user who types "I am an administrator" supplies all the evidence the rule asks for. OWASP says it plainly: privilege separation and authorization bounds checks "must not be delegated to the LLM, either through the system prompt or otherwise." Its excessive agency entry names the alternative, which is to implement authorization in downstream systems rather than let the model decide whether an action is allowed.

Sources: OWASP, LLM07:2025 System Prompt Leakage and LLM06:2025 Excessive Agency.

Never pass model output to eval or a shell

Model output is shaped by the prompt, and part of the prompt comes from whoever talks to the agent or feeds it content. OWASP's improper output handling entry gives the result of forgetting that: model output entered directly into a system shell, exec or eval, resulting in remote code execution. Its advice is to treat the model as any other user and validate its responses before they reach backend functions.

In Python, subprocess does not call a shell unless asked, so arguments passed as a list reach the program without shell interpretation. With shell=True, the documentation leaves quoting every metacharacter to the application. A tool that needs a program runs it with a fixed argument list, never with a command string the model wrote.

Sources: OWASP, LLM05:2025 Improper Output Handling; Python documentation, subprocess, Security Considerations.

A dispatcher that enforces the checks

We wrote this minimal dispatcher to show the checks in one place. It is illustrative code, not a library, and it needs Python 3.9 or later for is_relative_to:

import re
import subprocess
from pathlib import Path

WORKSPACE = Path("/work/project").resolve()
BRANCH = re.compile(r"[A-Za-z0-9._/][A-Za-z0-9._/-]{0,99}")


def read_file(path: str) -> str:
    target = (WORKSPACE / path).resolve()
    if not target.is_relative_to(WORKSPACE):
        raise PermissionError("path is outside the workspace")
    return target.read_text(encoding="utf-8")


def delete_branch(name: str) -> str:
    if not BRANCH.fullmatch(name):
        raise ValueError("not an allowed branch name")
    subprocess.run(["git", "branch", "-D", name], cwd=WORKSPACE, check=True)
    return f"deleted {name}"


TOOLS = {
    "read_file": {"run": read_file, "args": {"path": str}, "approve": False},
    "delete_branch": {"run": delete_branch, "args": {"name": str}, "approve": True},
}


def dispatch(call: dict, ask_user) -> dict:
    name = call.get("name")
    spec = TOOLS.get(name) if isinstance(name, str) else None
    if spec is None:
        return {"is_error": True, "content": "unknown tool"}
    args = call.get("input")
    if not isinstance(args, dict) or set(args) != set(spec["args"]):
        return {"is_error": True, "content": "arguments do not match the tool"}
    for key, kind in spec["args"].items():
        if not isinstance(args[key], kind):
            return {"is_error": True, "content": f"{key} must be {kind.__name__}"}
    if spec["approve"] and not ask_user(call["name"], args):
        return {"is_error": True, "content": "the user declined this call"}
    try:
        return {"content": spec["run"](**args)}
    except (ValueError, OSError, subprocess.CalledProcessError) as err:
        return {"is_error": True, "content": str(err)}

Each check maps to one rule from the sections above:

We ran the dispatcher against a temporary directory, with subprocess.run replaced by a recorder so no git command ran. It read a file inside the workspace and refused 11 bad calls: an unknown tool, a tool name that is not a string, an extra key, a list for a string, a .. path, the sibling-prefix path, an absolute path outside the workspace, a symlink pointing outside, a declined approval, a branch name starting with a dash, and a branch name containing a semicolon. The one approved deletion produced the only recorded call, ["git", "branch", "-D", "old-feature"], with no shell.

Sources: our run; Python documentation, pathlib; NVD, CVE-2025-53110.

Tool results are untrusted input

The checking does not stop when the tool returns. As our file-read trace shows, a tool result goes into the next request and becomes context for the model's next decision. If the result holds text an attacker wrote, such as a web page, a document or a file in a cloned repository, that text can carry instructions. MITRE ATLAS calls this indirect prompt injection, AML.T0051.001: prompts injected through a separate data channel the agent ingests, which let an adversary act against the user with whatever privileges the AI system holds.

Three defenses meet at the result:

A model stands outside a platform that holds a dispatcher facing the model, a mark named Error returned, the read_file tool and a panel named Approval prompt. Lane 1 runs from the model to the dispatcher. Lane 2 ends at the error mark, lane 3 reaches the read_file tool, lane 4 returns to the model, and lane 5 ends at the approval prompt. At the end a card tagged run_shell: not in the table rests at the error mark, a card tagged read_file at the tool, a block tagged Tool result: untrusted at the model, and a card tagged delete_branch at the approval prompt.
  1. The harness receives a proposal: a tool call from the model is a proposal, and only the harness turns it into an action; the dispatcher in this post enforces its checks.
  2. An invented tool gets an error: a model that invents run_shell gets an error, not a shell.
  3. A read inside the workspace runs: in our run the dispatcher read a file inside the workspace.
  4. The result is untrusted input: a tool result goes into the next request, and if it holds text an attacker wrote, that text can carry instructions.
  5. A later call meets the approval prompt: the dispatcher checks every later call on its own terms, so a result that talks the model into requesting delete_branch still meets the approval prompt.
The read is from our run of the dispatcher against a temporary directory, which also refused an unknown tool. The last call is the case where a tool result has talked the model into requesting delete_branch.

OWASP also says it is unclear whether any method prevents prompt injection completely, which is why these checks live in code the model cannot rewrite.

Sources: MITRE ATLAS, AML.T0051.001 LLM Prompt Injection: Indirect; Tools, MCP specification 2026-07-28; OWASP, LLM01:2025 Prompt Injection.

Excessive agency is the failure these checks prevent

OWASP's LLM06:2025 names the whole pattern: excessive agency lets damaging actions happen in response to unexpected, ambiguous or manipulated model output, whatever caused the model to misbehave. Its three root causes map onto the dispatcher:

OWASP's mitigations read like a checklist for a harness: offer only the tools the task needs, avoid open-ended tools such as running a shell command or fetching a URL, require human approval for high-impact actions, and enforce authorization outside the model.

Source: OWASP, LLM06:2025 Excessive Agency.

Where to go next

Tools that arrive from MCP servers add one more risk, because the server itself may be the attacker, and MCP servers your coding agent should not trust covers that side. To see where the harness and its tools run on the host or in a container, read Running coding agents on the host and in containers.