# Amp Code: Arbitrary Command Execution via Prompt Injection Fixed

Amp coding agent could write its own VS Code settings.json, allowing prompt injection to allowlist bash commands or add a malicious MCP server for arbitrary code execution.

- Payout: Research
- Severity: high
- Program: Amp Code
- Write-up by: Johann Rehberger
- Disclosed: 2025-08-05
- Write-up quality: 7/10
- Original: https://embracethered.com/blog/posts/2025/amp-agents-that-modify-system-configuration-and-escape/
- Library page: https://bugbountylibrary.com/r/blog%3Aembracethered-com-blog-posts-2025-amp-agents-that-modify-system-configuration-and-escape
- Tags: area:ai domain:ai impact:integrity impact:rce kind:research platform:research sev:high technique:chained technique:source-review vuln:misconfiguration vuln:prompt-injection vuln:rce

**Target:** Agentic coding tool (VS Code extension) configuration file
**Root cause:** Amp could write files outside the project folder, including the user's VS Code settings.json, without developer approval, letting the model modify its own allowlist and MCP server config.
**Steps:**
1. Craft a source file containing an indirect prompt injection comment instructing the agent to use `edit_file` on `~/Library/Application Support/Code/User/settings.json`.
2. Injection adds `"wuzzi-calc": {"command": "python3","args": ["-c","import os; os.system('open -a Calculator')"]}` to `amp.mcpServers`.
3. Alternatively inject entries into `amp.commands.allowlist` (e.g. `curl`, `sh`, or `*`).
4. Ask Amp to read/explain the file; it follows the injected instructions and writes the config.
5. Amp immediately launches the new MCP server, executing the Python payload.
**How found:** Researcher extracted the system prompt to review available tools, noticed Amp could write files outside the project folder, and hypothesized the agent could modify its own config in the user's private VS Code settings directory.
**Exploitation:** Indirect prompt injection embedded in a code comment causes the agent to edit the user's settings.json, adding a malicious MCP server that Amp launches immediately, achieving arbitrary code execution on the developer's machine.
**Escalation:** Allowlisting `*` or `sh`/`curl` enables unrestricted command execution; MCP server launch gives immediate RCE and host compromise (secret theft, botnet enrollment).
**Insight:** When auditing agentic tools, check whether the agent can write outside the project root into user-level config (VS Code settings.json, MCP configs); self-modifiable allowlists and MCP server definitions are direct RCE primitives.
