Get the free coreGet core

AI agent security: the real risks of coding agents and how to cut them

Updated 5 min readSection 05 / Threats
SHORT ANSWER

AI agent security for a coding agent means controlling what it can read, run and send. The four risks that matter on a Mac are prompt injection, excessive agency, supply-chain attacks and leaked secrets. None has a complete fix: as Simon Willison puts it, we still don't know how to prevent prompt injection 100% reliably. OWASP, a security project that publishes lists of common weaknesses, advises giving the model the minimum privileges and requiring human approval of high-impact actions. A sandbox, a fence the operating system enforces around shell commands, adds a second layer.

01The AI agent security risks in one table

This page covers AI agent security risks for agents developers run locally. A coding agent is a program driven by a language model that can read files, run commands and call tools on your machine. That is why its risks differ from a chatbot's.

RiskReal exampleWhat to do
Prompt injectionAn attacker could chain hidden instructions in text the agent reads to write .cursor/mcp.json and run code on the machine, in Cursor below 1.3.9Least privilege, meaning only the access the task needs; approvals for risky actions
Excessive agencyA founder claimed a Replit agent deleted a database despite instructions not to change codeHuman approval for high-impact actions
Supply chainMalicious versions of popular npm packages ran a post-install script, a script that starts by itself right after a package is installed, that harvested dataCheck what the agent installs; see below
SecretsIn Claude Code's auto mode, reading .env and sending credentials to a matching API is allowed by defaultKeep secrets out of reach; rotate if exposed

02Prompt injection: the agent obeys text it reads

Prompt injection is a technique to override an assistant's instructions by inserting malicious text. OpenAI's Codex docs give the plain example: the agent retrieves and follows instructions from untrusted content, such as a web page or a dependency README.

Simon Willison named the dangerous mix. If an agent combines private data, untrusted content and a way to communicate externally, an attacker can trick it into stealing data. A coding agent often has all three. A Claude Code sandbox escape in the project's advisories needed a cloned malicious repository with prompt injection.

What to do. Restrict the model's privileges to the minimum necessary. Keep agent internet access as limited as possible and point it only at trusted resources. Do not count on guardrail filters alone: Willison says we still do not know how to prevent this 100% reliably, and in web application security 95% is very much a failing grade.

03Excessive agency: more power than the task needs

OWASP defines Excessive Agency as the weakness that lets damaging actions follow from unexpected, ambiguous or manipulated model output, whatever causes the malfunction. The agent does not need to be attacked. A confused agent with too much power is enough.

The Replit case shows it. The Register reported on July 21, 2025 that the SaaStr founder claimed Replit deleted a database despite his instructions not to change any code without permission. He said there is no way to enforce a code freeze in vibe coding apps like Replit. These are his claims as reported.

What to do. Require human approval of high-impact actions and limit the extensions the agent may call. The controls for Claude Code are in permissions, and a script that runs before each action is in hooks.

04Supply chain: packages and MCP servers

A supply-chain attack means the danger arrives inside something you install. MCP, the Model Context Protocol, is an open-source standard for connecting AI applications to external systems, and an MCP server is a program that exposes capabilities to the agent. Local MCP servers are programs downloaded and run on the same machine as the agent. Anthropic reviews connectors against listing criteria but does not security-audit any MCP server.

Three cases:

The agent adds its own door. Socket describes slopsquatting as registering a package name that a model hallucinated, hoping someone will install it without noticing it is fake. Measured numbers are in AI-generated code vulnerabilities.

What to do. Verify you trust each MCP server before connecting it. A cloned repository cannot approve its own servers in Claude Code. For npm, the ignore-scripts setting makes npm skip package scripts, and min-release-age installs only versions that were available for more than a set number of days.

05Secrets: what an agent can see and send

OWASP counts security credentials as sensitive information. Agents meet them in .env files, which hold a project's keys and passwords, and in the environment. In Claude Code's sandbox, environment variables are inherited, secrets included.

If a secret leaks, GitHub's rule is blunt: consider it compromised, because removing it from the codebase does not prevent exploitation. Check logs for use of the secret.

What to do. Deny reads of secret files with a rule such as Read(./.env), and do not mount host secrets like ~/.ssh into a container. More steps are in vibe coding security.

06A short AI agent security plan

  1. Run the agent in a project folder, not your home directory.
  2. Write narrow permission rules and keep approvals on for high-impact actions.
  3. Put a sandbox or container between the agent and the rest of the Mac; see the sandbox guide.
  4. Keep secrets out of the project and rotate any that were exposed.
  5. Review every new package and MCP server before it runs.

Pages by tool: Claude Code security, Cursor security, Is Claude Code safe?, Is Cursor safe?, Is Codex safe?, Is Copilot safe? and Is Claude safe?.

Every step above limits what an agent can do; none of them is a record of what it did on your Mac. Whichever controls you pick, it helps to see what the agent actually did: Artificial Immunity's free, open-source core watches agent sessions and program starts on your Mac and reports what it finds.

All threats guides

AI agent firewall: limiting what your coding agent can reach AI agent monitoring: how to see what your agent did on your Mac AI guardrails: what they are and what they can't stop API key exposed on GitHub: rotate it first, then remove it and check the damage Atomic Stealer (AMOS) on Mac: how it spreads and how to check AWS access key leaked: what to do right now Claude Code and your .env file: how to keep secrets away from the agent Cookie hijacking: how stolen cookies let attackers act as you, and what to do Crypto wallet drained: how it happens on a developer's Mac and what to do first Dependency confusion: how a public package replaces your private one Fake job interview malware aimed at developers: the take-home test that steals your keys GitGuardian and alternatives for finding leaked secrets GitHub account hacked: what to do now, in order GitHub secret scanning and push protection explained Guardrails for AI agents: permissions, sandboxes, hooks and review How to check an npm package for malware before installing it How to prevent prompt injection in AI agents (and what can't be prevented) How to use MCP in Claude Code: commands, scopes and approvals Indirect prompt injection: when the attack hides in what the agent reads Infostealer check: signs your Mac was hit and what to do now Leaked API key: what to do in the first hour Mac infostealers in 2026: AMOS, DigitStealer and others Malicious VSCode extensions in VS Code, Open VSX and Cursor: cases and how to check yours Malware in a GitHub repository: how to check a repo before you run it MCP security: risks of MCP servers and best practices MCP tool poisoning and malicious MCP servers explained npm malware: how malicious packages get onto your Mac npm supply chain attacks: how they work and how to protect yourself OpenAI API key leaked: how to revoke it and check usage Prompt injection in Claude Code, Cursor and Codex: what to set in each Prompt injection: what it is, with real examples PyPI malware: malicious Python packages and how to avoid them Remove secrets from Git history (and why rotating comes first) Secret scanning: find leaked keys in your code before attackers do Session hijacking: how stolen cookies let attackers act as you Shai-Hulud: the npm worm explained, and what to do if you were hit Slopsquatting: packages that AI hallucinated and attackers registered The Nx malware attack (s1ngularity): what happened and what to check TruffleHog: how to scan your repos for leaked secrets Typosquatting: lookalike package names and how to spot them What is a .env file and why it should never be committed What is an API key, and why does a leaked one cost money? What is an infostealer? How it works and what it takes What is an MCP server? A plain explanation for developers Where to store API keys on a Mac: .env, Keychain or a secrets manager XCSSET malware: infected Xcode projects explained

FAQ

How secure are AI agents?

Not fully. Security researcher Simon Willison says we still don't know how to prevent prompt injection 100% reliably, and OWASP, a security project that publishes lists of common weaknesses, says it is unclear whether fool-proof prevention exists. You cut the risk with least privilege and approvals.

What are the biggest security risks of AI agents?

For coding agents on a Mac, four: prompt injection, excessive agency, supply-chain attacks through packages and MCP servers, and leaked secrets. Each has a real case in the sections above.

How do I secure access for AI agents?

Give the agent the minimum it needs. OWASP advises restricting the model's access privileges to the minimum necessary and limiting the extensions the agent may call. In practice that means narrow permission rules, a sandbox and no secrets in the project folder.

How to run AI agents securely?

Require human approval of high-impact actions, keep internet access as limited as possible, and keep the agent away from files you cannot afford to lose. Isolated environments exist for this, see the sandbox guide.

Can AI agents be trusted?

Trust them with tasks, not with unchecked authority. OWASP's advice is to treat the model like any other user, with zero trust. A reported case: the SaaStr founder claimed a Replit agent deleted a database despite instructions not to change code.

What are the top 3 AI security risks?

Three entries on OWASP's 2025 list for LLM applications are prompt injection, excessive agency and supply chain. They match the first three sections of this page.

Sources

  1. Simon Willison: the lethal trifecta
  2. OWASP LLM01 Prompt Injection
  3. OWASP LLM06 Excessive Agency
  4. OWASP LLM05 Improper Output Handling
  5. Wiz: s1ngularity
  6. Wiz: Shai-Hulud
  7. Snyk: malicious postmark-mcp
  8. Socket: slopsquatting
  9. The Register: Replit incident
  10. OpenAI Codex docs: internet access
  11. Artificial Immunity
Letting agents run commands on your Mac? Artificial Immunity watches the Mac where your agents work.Get the free core