Skip to main content
Back to Blog

How to Secure AI Agents: OWASP Agentic Top 10, MCP and Key Controls

Updated on November 19, 20267 minutes read


An AI agent, built around a large language model (LLM), does more than answer questions. It plans, calls tools, reads and writes data and sometimes talks to other agents. That raises the stakes of every model weakness: a prompt injection that would only produce a bad answer in a chatbot can make an agent send email, change records or run code. This guide covers the OWASP Top 10 for Agentic Applications and practical controls, including Model Context Protocol (MCP) security.

Why Agents Need Their Own Security Model

NIST AI 100-2e2025 describes an agent as software that "iteratively prompts a model", processes its outputs, for example to call a function, and feeds the results back into the next prompt. The OWASP Top 10 for LLM Applications 2026 draws the line there: it covers the model as a component, and once the model acts with tools, memory and downstream consequences, OWASP points to its agentic list.

That list adds a principle worth adopting first: least agency. OWASP advises organizations "to avoid unnecessary autonomy", because deploying agentic behavior where it is not needed "expands the attack surface without adding value".

The OWASP Top 10 for Agentic Applications

The OWASP GenAI Security Project released the OWASP Top 10 for Agentic Applications on 9 December 2025. Its ten entries:

  • ASI01: Agent Goal Hijack. Injected content redirects the agent's goals or plans.
  • ASI02: Tool Misuse and Exploitation. The agent uses legitimate tools in unsafe ways.
  • ASI03: Identity and Privilege Abuse. Delegated or inherited credentials are abused.
  • ASI04: Agentic Supply Chain Vulnerabilities. Tools, MCP servers, prompts or agents are malicious or tampered with.
  • ASI05: Unexpected Code Execution (RCE). Generated or injected code runs on your systems.
  • ASI06: Memory & Context Poisoning. Stored memory or retrieved context is corrupted.
  • ASI07: Insecure Inter-Agent Communication. Messages between agents are spoofed or altered.
  • ASI08: Cascading Failures. One fault spreads across agents and workflows.
  • ASI09: Human-Agent Trust Exploitation. People over-trust a confident agent.
  • ASI10: Rogue Agents. An agent drifts from its intended function or scope.

Give Agents Least Privilege and Scoped Credentials

OWASP's LLM01:2026 entry notes that most high-impact prompt injection incidents on record became severe because the compromised model could act through tools at the user's privilege level. ASI03 recommends per-agent identities and "short-lived, narrowly scoped tokens per task"; ASI02, per-tool profiles with scopes, rate limits and egress allow-lists. Run tools in the user's own context with the minimum OAuth scope, not through a shared high-privilege account.

Invariant Labs showed why scope matters: a malicious GitHub issue could hijack an agent connected to GitHub's MCP server and expose data from the user's private repositories. They called it "not a flaw in the GitHub MCP server code itself" but an architectural issue, and suggested limiting each session to one repository.

A quick design check is Meta's Agents Rule of Two: in one session, an agent should combine no more than two of processing untrustworthy inputs, accessing sensitive systems or private data, and changing state or communicating externally. If it needs all three, Meta says it "should not be permitted to operate autonomously".

Use Allow-Lists and a Policy Check Outside the Model

Decide in code, not in the prompt, what the agent may do. Allow-list the tools for each task, the network destinations it can reach and the commands it may run without asking, and deny everything else. ASI02 describes a policy enforcement point that treats the planner's output as untrusted and checks intent and arguments, enforces schemas and rate limits, and issues short-lived credentials before a tool runs.

Sandbox Any Code the Agent Runs

If an agent writes or runs code, plan for some of it to be hostile (ASI05). OWASP's advice: never run as root, run code in sandboxed containers with strict limits including network access, and separate code generation from execution with validation gates. Anthropic's write-up on sandboxing its coding agent adds that effective sandboxing needs both filesystem and network isolation, since without network isolation a compromised agent "could exfiltrate sensitive files like SSH keys".

Ask a Human Before Irreversible Actions

Require approval before anything hard to undo or visible outside the system: deleting data, moving money, publishing or sending messages. ASI02 suggests showing a dry-run or diff of the action before approval. Keep prompts rare enough to matter: OWASP warns that approval fatigue weakens judgment, and ASI09 describes agents that talk reviewers into approving harmful actions.

Treat MCP Servers and Tool Descriptions as Untrusted

MCP makes it easy to plug tools into an agent, which makes tools a supply-chain risk. The MCP specification says clients "MUST consider tool annotations to be untrusted unless they come from trusted servers" and that there "SHOULD always be a human in the loop with the ability to deny tool invocations".

Invariant Labs describes tool poisoning as instructions in tool descriptions that "are invisible to users but visible to AI models", and warns that a server can change a description after you approved it. OWASP's ASI04 cites a malicious MCP server on npm that impersonated a legitimate email integration and secretly copied emails to the attacker.

Practical steps:

  • Install MCP servers from sources you trust, pin versions and verify hashes.
  • Review tool descriptions for hidden instructions, and again when they change.
  • For local servers, show the exact command before it runs and launch it with minimal privileges in a sandbox, as the MCP security best practices recommend.
  • Never pass tokens through: MCP servers "MUST NOT accept any tokens that were not explicitly issued for the MCP server".
  • Start with narrow OAuth scopes and add more only when an operation needs them.

Module 4 of the self-paced AI Security: Securing LLM Apps & AI Agents course covers securing AI agents, tools and MCP servers.

Keep Agent Memory Clean

Memory lets an attack persist across sessions (ASI06). Validate what gets written to memory, keep memory separate per user and per task, expire entries that have not been verified, and don't let the agent's own outputs flow back into trusted memory automatically. OWASP's LLM01:2026 entry adds: treat memory writes as privileged and log the prompt behind each one.

Log Agent Actions and Keep a Way to Stop the Agent

Keep tamper-evident logs of tool calls, approvals and messages between agents, so you can investigate and roll back (ASI08, ASI10). Make sure you can stop an agent fast: OWASP lists kill switches and credential revocation for rogue agents, and circuit breakers with step, time and cost limits for runaway runs. Test the stop path before you need it, and red-team agents regularly, only on systems you own or have written permission to test, and check that your model provider's terms allow security testing.

  • Not every AI system is high-risk under the EU AI Act: broadly, only those used for a purpose listed in Annex III (with exceptions), or that are a safety component of a product covered by the EU laws listed in Annex I (or such a product themselves) when that product needs a third-party conformity assessment.
  • For high-risk AI systems, Article 15 requires "an appropriate level of accuracy, robustness, and cybersecurity". Article 15(5) adds resilience against attempts by unauthorized third parties to alter a system's use, outputs or performance, and lists, where appropriate, measures against data poisoning, model poisoning, adversarial examples (model evasion), and confidentiality attacks or model flaws.
  • After Regulation (EU) 2026/1744, the "Digital Omnibus on AI" (in force 27 July 2026), the high-risk obligations apply from 2 December 2027 for Annex III systems and from 2 August 2028 for systems in products under Annex I.
  • Some rules apply already: under Article 50, from 2 August 2026, providers of AI systems that interact directly with people must make sure those people are told they are dealing with an AI, unless it is obvious.
  • The Cyber Resilience Act applies to products with digital elements, software included, placed on the EU market, so check whether your agent ships as such a product or runs as a service. It entered into force on 10 December 2024. Manufacturers' reporting obligations for actively exploited vulnerabilities and severe incidents apply from 11 September 2026, and the main obligations apply from 11 December 2027.

Whether any of this applies to your agent is a question for legal counsel.

Where to Go Next

If you are new to building agents, our guide on how to build an AI agent and the self-paced Agentic AI: Intro to Agent Development course cover the basics.

One structured way to build these skills is the AI Security: Securing LLM Apps & AI Agents course: self-paced, Intermediate level and 40 hours long. It covers AI supply chain security and the EU rules, and its capstone asks you to attack, fix and re-test an AI agent.

Learn technical skills online with Code Labs Academy

Learn technical skills online with Code Labs Academy

Join our supportive community, unlock your potential, and embark on a rewarding career path.

Apply Now

Frequently asked questions

What is the OWASP Top 10 for Agentic Applications?

It is a list of the ten highest-impact security risks for AI agents, released by the OWASP GenAI Security Project in December 2025. Its entries run from ASI01 Agent Goal Hijack to ASI10 Rogue Agents, each with examples and mitigations.

What does least agency mean for AI agents?

Least agency is OWASP's extension of least privilege: give an agent only the autonomy its task needs. Agentic behavior that is not needed expands the attack surface without adding value.

Are MCP servers safe to use?

Treat them like any third-party code, because a server's tools and tool descriptions can carry hidden instructions. Install them from sources you trust, pin and verify versions, review tool descriptions, run local servers in a sandbox and keep a human able to deny tool calls.

Should an AI agent ask for approval before every action?

No. Ask a person before high-impact or irreversible actions such as deleting data, moving money or sending messages, and let low-risk, reversible actions run. Too many prompts lead to approval fatigue, which weakens the review.

Is every AI agent high-risk under the EU AI Act?

No. Broadly, only AI systems used for a purpose listed in Annex III of the Act (with exceptions), or that are a safety component of a product covered by the EU laws in Annex I (or such a product themselves) when that product needs a third-party conformity assessment, are high-risk. Whether a specific agent falls into one of them is a question for legal counsel.

Career services

Personalized career support to help you launch your tech career. Get résumé reviews, mock interviews, and industry insights, so you can showcase your new skills with confidence.

Explore