Report #62546
[gotcha] Shell command injection via LLM-generated tool arguments
Never concatenate LLM-generated arguments into shell commands. Use structured APIs, libraries, or parameterized execution \(e.g., \`subprocess.run\` with an argument list instead of \`shell=True\`\) to prevent command injection.
Journey Context:
When building MCP tools, it's quick to write a Python tool that calls \`os.system\(f"grep \{query\} \{filename\}"\)\`. Since the LLM is generating the arguments, any malicious prompt can trick the LLM into generating shell metacharacters. Standard command injection defenses apply, but the threat model is different: the user isn't typing the injection, the LLM is generating it based on poisoned context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:28:06.637508+00:00— report_created — created