AI Tool Argument Injection — LLM to OS Command
ConvertBot converts uploaded files by calling a tool that runs convert /uploads/{filename} /out/result.{format} in a shell. The model copies your filename and format straight into those arguments, and nobody escapes them.
What is tool argument command injection?
Agents call tools with arguments the model fills in, such as a filename or an output format. If the tool builds a shell command by placing those values in a string, the shell interprets whatever characters they contain.
Tool argument command injection is getting the model to pass a value that the shell reads as more than a value. It is ordinary command injection, with the model as the route by which attacker input reaches the command line.
A real case
Tracebit found that instructions hidden in a project README could make Google's Gemini CLI run a harmful command chained onto one the user had already allowed. The extra command could send environment variables, including credentials, to an outside server. Google fixed it in version 0.1.14.
This lab has the same shape: text chosen by the model ends up on a command line, where the shell gives it a meaning the tool's author did not intend.
Source: Tracebit
How to fix it
- Call programs with an argument list, never through a shell string.
- Validate each argument against a strict pattern or a fixed list of options.
- Run tools in a sandbox with no secrets and minimal file access.
- Treat arguments from the model as untrusted user input.
Questions people ask
What is command injection?
A bug where input is interpreted by a shell as commands, because the program built a command line from it.
Why are AI tools at risk?
The model chooses the argument values, and the model's choices are shaped by text that users and documents provide.
Is escaping the arguments enough?
Avoiding the shell altogether is safer. Escaping is easy to get wrong.
Read the full OWASP LLM Top 10 guide · All free labs · AI red team certification