← Lab /Security & privacy

Trusted coding-agent projects can execute attacker code before any prompt

Opening a trusted repository in a coding agent can cause attacker-controlled code to run before the first user prompt without any model response or shell-command approval.

Security & privacy Datadog Security Labs 3 Aug 2026 Attack Prototype evidence

Published as “Before the first prompt: Code execution paths in trusted coding-agent projects”

Why it matters

Developers should treat opening a repository in a coding agent as executing untrusted code and use disposable environments and runtime monitoring to mitigate risk.

Summary

The authors examined how coding agents (Codex and Claude Code) start up after a repository is trusted. They discovered two execution paths-project-scoped MCP configuration in Codex and a malicious PATH environment variable in Claude Code-that launch attacker-controlled processes immediately on project open. No model response or user-approved shell command is required, and the code runs before any prompt is sent. Their evidence consists of local tests on the two agents, showing automatic process launch and successful payload execution.

What they found 2

  1. Codex MCP configuration can start an attacker-controlled process as soon as the project is opened.

    “When the malicious project is opened, code execution happens immediately. There is no need to trick the user to interact or call the MCP server in any way.”

  2. Both paths work without any model response or shell-command approval.

    “In our tests, Codex MCP configuration and Claude Code project environment settings created automatic code-execution paths without a model response or shell-command approval.”

Caveats 4

  • Legitimate Git and MCP activity can make any one of these signals noisy on its own.
  • Codex now requires review of hook definitions but does not attest to the contents of scripts or executables referenced by those definitions.
  • Detection may generate false positives because normal Git and MCP activity appear similar to malicious behavior.
  • The findings are demonstrated on current versions of Codex and Claude Code and may not apply to future releases.

What’s new here 4

  • Identify MCP server configuration as a pre-prompt code execution vector in Codex.
  • Show that overriding the PATH in Claude Code can run a malicious git wrapper on startup.
  • Provide a searchable regex command to locate potential execution controls in a repository.
  • Introduce Datadog AI Guard for Coding Agents as a runtime mitigation.