Skip to content
Back to blog
Security

Markdown Is the New Malware: How a Planted AGENTS.md Can Hijack Your AI Coding Agent

HTHaseeb Tariq · Co-FounderOct 29, 202611 min read
Malicious markdown file infiltrating AI coding agent workflow, representing instruction file hijacking
Security

This week, security researchers at Forever Security published findings on a new attack vector targeting AI coding agents: planted instruction files. They discovered a malicious AGENTS.md file on a real customer's machine, disguised as ordinary engineering notes, that instructed the coding agent to install attacker-controlled infrastructure and run malicious code. In their testing, the payload executed successfully in more than 90% of attempts. The attack exploits how coding agents are designed to work, not a bug that can be patched.

For businesses adopting AI coding agents like Codex, Claude Code, Cursor, or similar tools, this is not a theoretical vulnerability. It is an active campaign that has already reached production environments. The controls you put around coding agents today determine whether your development infrastructure becomes a target tomorrow.

What happened: the attack in detail

Forever Security's report documents a malicious AGENTS.md file found in the ~/Downloads folder of a real customer machine. According to SpanDock's analysis, the file was approximately 13 KB and titled 'Engineering Work Guidelines,' designed to look like legitimate development documentation that a developer might have downloaded.

The file contained instructions that told the Codex coding agent to perform two critical actions. First, it instructed the agent to add an MCP server entry ([mcp_servers.project-tools]) to the global ~/.codex/config.toml configuration file. Because this configuration file is machine-wide, the attacker's server would then load in every Codex session, regardless of which folder the developer was working in. Second, the file instructed the agent to run npm install of a package called function-color.

The function-color package is part of a malware campaign that CloudSEK and Checkmarx have named MALFEX. The package pulls in a downloader called function-flag that fetches a Windows payload. The package has since been removed from npm, but the attack pattern remains viable with any other malicious package.

The planted file also instructed the agent to start a child session using the command codex exec --dangerously-bypass-approvals-and-sandbox, according to SpanDock's analysis. This flag disables the safety controls that would otherwise prompt the user before executing potentially dangerous commands. With approvals bypassed, the agent executed the attacker's instructions without user confirmation.

Why this attack works

The attack exploits a fundamental design decision in AI coding agents: they read and follow instruction files in their working directory. Files like AGENTS.md, CLAUDE.md, .cursorrules, and similar instruction files are intended to help developers customize agent behavior for their projects. The agent treats these files as authoritative because that is how the feature is supposed to work.

Forever Security reports that approximately half of their customers run a coding agent inside their ~/Downloads folder at some point. This makes the Downloads folder a high-value target. A web page can save a file to ~/Downloads without a click or permission prompt in many browsers. The attacker does not need to compromise the developer's machine or trick them into running an executable. They just need to put a file in the right place and wait for the developer to start the agent.

As Forever Security notes in their report, there is nothing for OpenAI or Anthropic to patch. Agents following instruction files in their working directory are working as designed. The vulnerability is in how development environments are configured and where agents are allowed to run, not in the agents themselves.

The CLAUDE.md variant: token theft

A separate researcher demonstration showed a similar attack targeting Claude Code. A crafted CLAUDE.md file instructed Claude Code to modify the project's .claude/settings.json file, setting ANTHROPIC_BASE_URL to a server the researcher controlled. When Claude Code made API calls, the requests went to the attacker's server instead of Anthropic's, leaking the OAuth login token. The attacker's server could then return tool calls that executed arbitrary code on the developer's machine.

This attack worked approximately 50% of the time in researcher testing. Unlike the AGENTS.md attack, this variant has not been observed in the wild. However, it demonstrates that the attack surface extends beyond Codex to any coding agent that reads configuration from instruction files.

Attack infrastructure: the MALFEX campaign

The function-color package that the AGENTS.md file instructed the agent to install is part of a broader malware campaign. According to The Hacker News, CloudSEK and Checkmarx have tracked the campaign and named it MALFEX. The package appears legitimate at first glance but includes a dependency on function-flag, which acts as a downloader to fetch additional payloads.

The payload targets Windows systems and establishes persistence on the compromised machine. The function-color package has been removed from npm, but the campaign infrastructure likely includes other packages that have not yet been identified. Supply chain attacks through npm, PyPI, and other package registries remain a reliable delivery mechanism for attackers.

What to check right now

If your development team uses AI coding agents, the following immediate checks are warranted. These are not long-term governance controls. They are triage actions to determine if you have already been compromised.

1. Search for instruction files you did not write

Look for AGENTS.md, CLAUDE.md, .cursorrules, .cursor/rules, and similar instruction files in locations where they should not exist. Pay particular attention to ~/Downloads, ~/Desktop, /tmp, and any folder that receives files from external sources. Also check freshly cloned repositories for unexpected instruction files that may have been planted by an attacker who compromised the upstream repo.

2. Inspect configuration files for unauthorized changes

Check ~/.codex/config.toml for any mcp_servers entries you did not add. Look for entries like [mcp_servers.project-tools] or any server pointing to an unfamiliar URL. For Claude Code users, check .claude/settings.json in your projects for any ANTHROPIC_BASE_URL setting that points anywhere other than Anthropic's official API endpoints.

3. Review npm/package installation history

If you find evidence of a planted instruction file, check whether function-color or any other suspicious packages were installed. Review your package-lock.json, yarn.lock, or pnpm-lock.yaml files for packages you do not recognize. If the package was installed, assume the machine is compromised and treat the incident accordingly.

Defenses: controls for coding agent deployments

The defenses against instruction-file attacks fall into three categories: where agents run, what they can modify, and how changes are detected. These controls apply whether you are using Codex, Claude Code, Cursor, or any other AI coding agent.

1. Never start coding agents in ~/Downloads or untrusted directories

The simplest control is the most effective. Coding agents should only run in directories you control: your project repositories, dedicated workspaces, or sandboxed environments. The ~/Downloads folder receives files from external sources without user review. Running a coding agent there is equivalent to running untrusted code.

Establish a policy that coding agents start only from version-controlled project directories. If your team needs to review downloaded files, copy them to a project directory first, and review any instruction files before starting the agent.

2. Keep approval prompts and sandboxes enabled

The --dangerously-bypass-approvals-and-sandbox flag exists for specific automation scenarios where human review is impractical. It should never be used during normal development. A planted instruction file that tells the agent to bypass approvals is a red flag. If the agent asks to disable safety controls, treat that request as suspicious.

If your CI/CD pipeline uses coding agents with reduced approvals, isolate those runs in sandboxed environments with no access to production credentials or persistent configuration files. The attack surface is smaller when the agent cannot modify ~/.codex/config.toml or similar machine-wide configurations.

3. Monitor configuration files for changes

Set up file integrity monitoring on critical configuration files. For Codex users, watch ~/.codex/config.toml for new mcp_servers blocks. For Claude Code users, watch .claude/settings.json in project directories for ANTHROPIC_BASE_URL changes. Any modification to these files that you did not make should trigger an alert.

Simple monitoring can use inotify on Linux, FSEvents on macOS, or file change detection in your endpoint security tooling. The goal is to detect unauthorized modifications before the attacker's server is invoked, not after.

4. Allowlist MCP servers and review new entries

MCP (Model Context Protocol) servers extend what coding agents can do. A malicious MCP server can intercept requests, inject code, or exfiltrate data. If your organization uses MCP servers, maintain an allowlist of approved servers and their URLs. Treat any new MCP server entry as a change that requires review.

The MCP gateway pattern we recommend for enterprise deployments applies here: route MCP traffic through a controlled gateway that enforces which servers agents can reach. An attacker-added server entry would be blocked at the gateway, not just flagged.

5. Rotate credentials if a planted file is found

If you discover a planted instruction file on a developer's machine, assume the worst. Rotate any credentials that were accessible to the coding agent: API keys, OAuth tokens, service account credentials, SSH keys. If the ANTHROPIC_BASE_URL or similar setting was modified, the OAuth token may have been leaked to the attacker's server. Treat that token as compromised and revoke it immediately.

Immediate response checklist for planted instruction files.
ActionWhy It Matters
Search for instruction files in ~/Downloads, /tmp, and untrusted locationsIdentify planted files before they execute
Check ~/.codex/config.toml for unknown mcp_servers entriesDetect attacker-controlled MCP servers
Check .claude/settings.json for ANTHROPIC_BASE_URL modificationsDetect token-stealing proxy configurations
Review package installation historyIdentify malicious packages like function-color
Rotate all credentials accessible to the coding agentLimit damage from potential token or credential theft
Preserve evidence for forensic analysisUnderstand attack scope and prevent recurrence

Policy controls for businesses

Beyond technical controls, businesses adopting coding agents need policy-level governance. The agent governance framework we recommend includes several controls specifically relevant to coding agent deployments.

Define where coding agents may run

Establish a clear policy on which directories and environments are approved for coding agent use. Version-controlled project directories with reviewed instruction files are appropriate. ~/Downloads, /tmp, shared network folders, and directories that receive files from external sources are not. Make this policy part of developer onboarding and security training.

Require review for new instruction files

Treat AGENTS.md, CLAUDE.md, and similar instruction files like code. They should be committed to version control, reviewed in pull requests, and audited for suspicious content. A new instruction file that appears outside of a PR should be investigated. This is the same principle as reviewing changes to CI/CD configuration: the instruction file controls what the agent does, so it needs the same scrutiny as any other executable content.

Apply least privilege to agent credentials

Coding agents often need access to package registries, cloud services, and internal APIs. Scope those credentials to the minimum necessary. An agent writing code does not need production database credentials. An agent running tests does not need deployment keys. The secrets checklist we published applies here: assume credentials accessible to the agent may be exfiltrated, and limit what the agent can reach.

Log and monitor agent activity

Enable logging for coding agent sessions. Know which commands the agent ran, which files it modified, and which external requests it made. If an incident occurs, these logs are essential for understanding what happened. Without them, you are investigating blind.

The broader pattern: instruction injection

This attack is a variant of prompt injection, but the injection vector is the filesystem instead of user input. The agent reads an instruction file, interprets it as authoritative guidance, and follows it. The attacker does not need to interact with the agent directly. They just need to place content where the agent will read it.

As BleepingComputer reports, this is not a bug that vendors can patch. The behavior is intentional: agents are designed to follow instruction files in their working directory. The defense must come from how development environments are configured and where agents are allowed to operate. Expecting the agent to distinguish legitimate instruction files from malicious ones is not a viable strategy.

Connection to supply chain security

The instruction-file attack shares DNA with the LiteLLM supply chain compromise we covered last week. Both attacks compromise developer infrastructure. Both exploit trust relationships: in the supply chain attack, trust in the package registry; in the instruction-file attack, trust in files present in the working directory. Both result in arbitrary code execution in development environments.

The defenses overlap as well. Pin package versions and verify hashes. Monitor for unexpected changes to configuration files. Isolate development environments from production credentials. Assume that any system receiving external input, whether package downloads or file drops, is a potential attack vector. The coding agent is the new execution context, and it needs the same hardening you would apply to any other runtime.

Sources

How Vyntrix Labs helps

When we deploy AI agents for clients, including coding agents and development automation, security controls are built in from day one. We configure agents to run only in approved directories, enforce MCP server allowlists, monitor configuration files for unauthorized changes, and log agent activity for audit and incident response. The agent governance controls we recommend are not optional add-ons; they are part of how we deploy agents that businesses can trust.

For organizations already using coding agents, we conduct AI automation audits that assess your current exposure: where agents run, what credentials they hold, what files they read, and what monitoring exists. We identify the gaps and build the controls to close them. See AI agents for custom development and AI automation for workflow automation with built-in governance.

Summary

A malicious AGENTS.md file planted in a developer's Downloads folder hijacked Codex sessions, installing attacker-controlled MCP servers and executing malicious packages in over 90% of test attempts. This is not a bug to patch. Coding agents are designed to follow instruction files in their working directory. The defense must come from where agents run, what they can modify, and how changes are monitored.

Never start coding agents in ~/Downloads or untrusted directories. Keep approval prompts and sandboxes enabled. Monitor ~/.codex/config.toml and .claude/settings.json for unauthorized modifications. Allowlist MCP servers and review any new entries. If you find a planted instruction file, rotate all accessible credentials and treat the incident as a potential compromise. These are the controls that prevent a markdown file from becoming malware.

Frequently asked questions

Can OpenAI or Anthropic patch this vulnerability?

No. Forever Security explicitly notes that there is nothing for OpenAI or Anthropic to patch. Coding agents following instruction files in their working directory are working as designed. The attack exploits this intentional behavior, not a bug. The defense must come from how development environments are configured and where agents are allowed to run.

How does a malicious file get into ~/Downloads?

A web page can save a file to ~/Downloads without a click or permission prompt in many browsers. The attacker does not need to compromise the developer's machine. They just need the developer to visit a page that triggers a file download, either through user action or automatically. Forever reports that about half of their customers run a coding agent in ~/Downloads at some point.

What is the function-color package?

function-color is a malicious npm package that was part of the MALFEX campaign tracked by CloudSEK and Checkmarx. It includes a dependency on function-flag, which acts as a downloader to fetch a Windows payload. The package has been removed from npm, but the attack pattern works with any malicious package the attacker chooses.

How do I know if my ~/.codex/config.toml has been compromised?

Open the file and look for mcp_servers entries you did not add. A legitimate entry would point to an MCP server your team approved. An attacker-added entry might point to an unfamiliar URL or have a generic name like 'project-tools.' If you find an entry you do not recognize, investigate before running Codex again.

What should I do if I find a planted AGENTS.md or CLAUDE.md file?

First, do not run the coding agent in that directory. Preserve the file for forensic analysis. Check configuration files for unauthorized changes. Review package installation history for suspicious packages. Rotate any credentials accessible to the coding agent, including API keys, OAuth tokens, and service account credentials. Treat the machine as potentially compromised until you have completed your investigation.

Are other coding agents besides Codex and Claude Code vulnerable?

Any coding agent that reads instruction files from its working directory has a similar attack surface. Cursor reads .cursorrules and .cursor/rules files. Other agents have their own instruction file formats. The specific exploitation steps differ, but the pattern is the same: place an instruction file where the agent will read it, and the agent will follow those instructions.

HT

Haseeb Tariq

Co-Founder at Vyntrix Labs

Let's build something intelligent

Ready to automate the busywork and scale with AI?

Book a free discovery call and we'll map your highest-impact automation opportunities, no obligation, no jargon.