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:
- 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 moretool_useblocks; - your code runs the operation and sends back a
tool_result; - 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:
- Allowlist the name:
TOOLS.getfinds nothing for a name outside the table, so a model that inventsrun_shellgets an error, not a shell, and a name that is not a string is refused the same way. - Check argument keys and types: the call must carry exactly the keys the tool declares, each of the declared type, so an extra
modekey or a list where a string belongs is refused before any handler runs. - Check values, not only types:
read_filecallsresolve(), which makes the path absolute, follows symlinks and removes.., and only then asksis_relative_towhether the result is inside the workspace. - Keep the value check in the right order: Python documents
is_relative_toas string-based, with no special handling of.., so calling it beforeresolve()would check a path that is not the one opened. - Know the limit of a path check: the dispatcher checks the path and then opens it in a second step, so a process that swaps a directory for a symlink between the two can still reach a file outside the workspace. The example assumes nothing untrusted can change the workspace during a call; when something can, enforce the boundary in the operating system too, for example with a container that mounts only the workspace.
- Compare components, not prefixes: the documented equivalent of
is_relative_towalks the path's parents, so a sibling namedproject-secretsnext toprojectfails, unlike the prefix match behind CVE-2025-53110. - Keep arguments from becoming options:
delete_branchaccepts only names that match a pattern and cannot start with a dash, so a name cannot turn into agitflag. - Least privilege: the table holds two narrow tools and no general shell, and
gitruns with a fixed argument list. - Human approval for risky tools:
delete_branchis marked for approval, and the dispatcher passes its exact arguments toask_userbefore it runs.
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:
- the MCP specification tells clients to validate tool results before passing them to the model;
- OWASP recommends separating and clearly marking untrusted content;
- the dispatcher checks every later call on its own terms, so a result that talks the model into requesting
delete_branchstill meets the approval prompt.

- 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.
- An invented tool gets an error: a model that invents
run_shellgets an error, not a shell. - A read inside the workspace runs: in our run the dispatcher read a file inside the workspace.
- 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.
- 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_branchstill meets the approval prompt.
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:
- excessive functionality, such as a tool meant to run one shell command that fails to stop others, is what the allowlist and the missing shell tool prevent;
- excessive permissions, such as a read feature that connects with an identity that can also update and delete, is what the workspace check and task-scoped credentials limit;
- excessive autonomy, a high-impact action with no confirmation, is what the approval prompt on
delete_branchremoves.
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.