Agentic AI Security: Complete Guide to Securing AI Agents
How AI agents change the attack surface, the threats that target them, and how to secure their identities, permissions and actions.
What Is Agentic AI Security?
Agentic AI security is the practice of protecting autonomous artificial intelligence systems that plan, make decisions, and execute multi-step tasks using tools and APIs. Unlike traditional Large Language Model (LLM) security, which focuses on filtering prompt inputs and text responses, agentic AI security protects the entire active execution loop, including reasoning paths, persistent memory, tool calls, identities, and runtime behaviors.
AI agents can independently plan workflows, call APIs, execute code, access enterprise applications, and communicate with other agents. These capabilities introduce security risks such as prompt injection, tool misuse, privilege escalation, memory poisoning, and unauthorized data access. A compromised agent may perform harmful actions across multiple connected systems without requiring direct human intervention at every step.
Identity plays a critical role in agentic AI security because agents need credentials and permissions to interact with external systems. Each agent must have a verifiable identity that allows organizations to authenticate requests, control access, and attribute actions to the correct agent and human user. Without effective identity and access management (IAM), compromised agents can misuse excessive permissions, impersonate trusted services, or access sensitive resources without proper authorization.
How Agentic AI Changes the Security Model
Agentic AI vs. Standalone LLM: Security Differences
The main security difference between standalone large language models (LLMs) and agentic AI is the ability to execute actions in connected environments. Standalone LLMs primarily generate responses based on user inputs, while AI agents can plan tasks, interact with external tools, access sensitive resources, and execute operations with varying degrees of autonomy. This expands the security attack surface from model inputs and outputs to the entire agent workflow.
The following table compares their security characteristics:
Agentic AI introduces greater operational security risks because malicious instructions can directly influence actions performed with legitimate permissions. For example, a prompt injection embedded in a retrieved document could cause an agent to access confidential files or execute unauthorized API requests. Securing agentic systems therefore requires visibility into tool calls, credential usage, and runtime behavior, alongside traditional LLM security controls.
Components of an AI Agent and Their Attack Surface
An AI agent typically consists of several components that work together to interpret goals, plan activities, retain context, and execute actions. Each component introduces an attack surface that adversaries may exploit to manipulate the agent or gain access to connected systems.
The main components and associated security risks include:
These components are interconnected, meaning that a compromise in one area can affect the entire agent workflow. For example, malicious content retrieved through a browser tool could influence the model's reasoning, alter the planner's next steps, and trigger an unauthorized API call. Effective agentic AI security requires controls across the entire execution chain, including input validation, memory integrity, tool authorization, and continuous monitoring.
The Lethal Trifecta: Private Data Access, Untrusted Content, and External Communication
The lethal trifecta is a security concept introduced by researcher Simon Willison to describe a particularly dangerous combination of capabilities in AI agents. It occurs when an agent can access sensitive information, process untrusted content, and communicate with external destinations. Together, these capabilities create an opportunity for attackers to use prompt injection to steal confidential information.
The three elements of the lethal trifecta are:
- Private data access: The agent has permission to retrieve sensitive information from internal databases, corporate documents, email accounts, or enterprise applications.
- Untrusted content: The agent processes externally controlled information, such as websites, emails, documents, repository files, or tool responses that may contain malicious instructions.
- External communication: The agent can send information outside the trusted environment through APIs, email, HTTP requests, messaging platforms, or other connected tools.
For example, an AI assistant with access to internal documents might encounter a malicious instruction embedded in a webpage it is summarizing. If the assistant treats that instruction as authoritative, it could retrieve confidential information and transmit it to an attacker-controlled endpoint.
Preventing this type of attack requires breaking the dangerous combination of capabilities wherever possible, using restricted data access, isolation of untrusted content, destination allowlisting, and independent authorization checks before sensitive actions. These safeguards are important because prompt filtering alone cannot reliably prevent every injection attempt.
Why Identity Is a Core Attack Surface for AI Agents
Identity is at the core of AI agent security, because it is key to monitoring agent actions and preventing their compromise by threat actors.
AI Agents as Non-Human Identities
AI agents are a type of non-human identity (NHI), similar to service accounts, workloads, and automated applications. However, traditional machine identities generally execute predefined operations, while AI agents can dynamically select tools, plan tasks, and initiate actions based on their goals and available context. This autonomy makes agent identities more difficult to govern using static permissions alone.
Each agent needs a distinguishable identity that can be authenticated, authorized, and monitored across its interactions with enterprise systems. Organizations that rely on shared service accounts or generic API credentials may struggle to determine which agent performed a particular action. This creates accountability gaps and makes it harder to investigate suspicious activity, enforce access policies, or revoke access for individual agents.
Delegated Access: Agents Acting on Behalf of Human Users
Delegated access allows AI agents to perform tasks using permissions granted by a human user. For example, an employee might authorize an agent to retrieve documents, update a project management system, or analyze customer records. In these scenarios, the agent operates on behalf of the user but should only access resources and perform actions explicitly permitted by the authorization context.
Security risks emerge when agents receive broader permissions than the user intended or fail to preserve authorization boundaries across multiple tools. An agent might retrieve information from one application and transfer it to another without considering data sensitivity or access restrictions. Delegation chains involving multiple agents can make it difficult to identify the original requester and determine whether individual actions remain authorized.
Risks of Static API Keys and Long-Lived Credentials in Agent Workflows
Many AI agents connect to enterprise systems using API keys, service account credentials, and authentication tokens. When these credentials are static or long-lived, they create persistent access paths that attackers can exploit. A compromised API key may allow an adversary to impersonate an agent and interact with connected systems without compromising the underlying AI model.
Credential exposure can occur through application logs, insecure configuration files, source code repositories, compromised tools, or malicious instructions that cause agents to reveal secrets. Long-lived credentials increase the potential impact because they may remain valid after the original task has ended. Shared API keys create additional problems by making it difficult to attribute individual actions to specific agents or sessions.
Key Requirements for AI Agent Authentication and Authorization
AI agents need verifiable identities and tightly controlled access to enterprise resources. Organizations should centralize authorization, limit permissions to each task, and enforce access controls throughout agent workflows rather than relying on static credentials or unrestricted token sharing.
Requirements for effective AI agent authentication and authorization:
- OAuth 2.1 and MCP authorization: Use centralized authorization servers, PKCE, and resource-specific tokens. MCP servers must validate token issuers and audiences and reject tokens intended for other services.
- Verified client registration: Prefer Client ID Metadata Documents (CIMD) where supported. Validate client metadata and redirect URIs, restrict dynamic registration, and require approval for sensitive integrations.
- Controlled agent delegation: Use token exchange and on-behalf-of delegation where supported. Preserve user and acting-agent context, restrict downstream permissions, and audit delegation chains instead of forwarding tokens across services.
- Fine-grained permissions: Evaluate each sensitive action using user, agent, resource, and contextual policies. Apply attribute- or relationship-based controls and require additional verification or human approval for high-impact operations.
- Short-lived tokens and rapid revocation: Issue narrowly scoped, task-limited tokens and protect refresh credentials. Use introspection or current authorization checks where immediate revocation is required; self-contained tokens may otherwise remain valid until expiration.
Top Agentic AI Security Threats
Agentic AI introduces security risks that extend beyond traditional large language model (LLM) vulnerabilities. Because AI agents can independently access enterprise data, invoke tools, communicate with other agents, and execute actions, attackers can exploit weaknesses across their identities, integrations, memory, and decision-making processes.
The OWASP Top 10 for Agentic Applications 2026 identifies ten major security risks associated with autonomous AI systems:
- ASI01 – Agent Goal Hijack: Attackers use prompt injection or manipulated content to redirect an agent from its intended objective toward unauthorized actions.
- ASI02 – Tool Misuse and Exploitation: Agents are manipulated into misusing legitimate tools, APIs, or system capabilities to perform harmful operations.
- ASI03 – Identity and Privilege Abuse: Compromised credentials, excessive permissions, or weak identity controls allow attackers to exploit an agent's access to sensitive resources.
- ASI04 – Agentic Supply Chain Vulnerabilities: Malicious or compromised dependencies, plugins, MCP servers, and third-party tools introduce vulnerabilities into agent workflows.
- ASI05 – Unexpected Code Execution: Agents execute malicious or unintended code through connected tools, generated scripts, or vulnerable execution environments.
- ASI06 – Memory and Context Poisoning: Attackers manipulate stored memory, retrieved information, or conversation context to influence an agent's future behavior.
- ASI07 – Insecure Inter-Agent Communication: Weak authentication and message validation allow attackers to impersonate agents or manipulate information exchanged between them.
- ASI08 – Cascading Failures: Incorrect decisions or compromised outputs propagate across connected agents and automated workflows, potentially causing widespread disruption.
- ASI09 – Human-Agent Trust Exploitation: Attackers exploit users' trust in AI-generated recommendations to encourage unsafe approvals or security decisions.
- ASI10 – Rogue Agents: Agents behave outside their intended objectives or operational boundaries, potentially taking unauthorized actions or resisting established controls.
The following table summarizes these threats, their potential consequences, and the security measures organizations can implement to reduce exposure.
4 Ways AI Agents Are Compromised
AI agents can be compromised when attackers manipulate the information, tools, or credentials they rely on to complete tasks. Unlike traditional applications, AI agents frequently process untrusted content alongside legitimate instructions and can execute actions using authorized access to enterprise systems. This creates opportunities for attackers to influence agent behavior without directly compromising the underlying AI model.
The following are four common attack methods targeting AI agents.
1. Prompt Injection Through Tool Responses
Attackers embed malicious instructions in information returned by tools that an AI agent uses, such as search results, database queries, documents, or web pages. When the agent processes this information, it may interpret the embedded instructions as legitimate commands rather than untrusted content.
For example, an agent retrieving information from an external website could encounter instructions directing it to access confidential files and transmit their contents to an unauthorized endpoint. Because the agent executes these actions through legitimate integrations, the resulting activity may appear authorized unless tool calls and data access are monitored.
2. MCP Tool Poisoning
Model Context Protocol (MCP) allows AI agents to connect with external tools and services. Attackers can exploit this integration by inserting malicious instructions into MCP tool descriptions, which agents read to understand a tool's capabilities and how to use it.
A compromised MCP server might advertise a legitimate function while embedding instructions that cause the agent to retrieve sensitive credentials or invoke unrelated tools. Attackers can also use tool shadowing to influence how agents interact with other trusted integrations. These attacks can succeed even when the malicious tool itself has limited permissions, because the agent may have access to more privileged resources.
3. Credential Theft Through Coding Agents
AI coding agents often operate within development environments and CI/CD pipelines, where they may have access to source code repositories, cloud credentials, API tokens, and deployment systems. Attackers can exploit this access by placing malicious instructions in pull requests, issue descriptions, support tickets, or other content the agent is expected to process.
For example, a malicious pull request comment could instruct an agent to execute a seemingly legitimate setup script. That script might collect environment variables containing authentication tokens and transmit them to an external server. If the agent inherits broad pipeline permissions, a single successful attack could expose multiple connected services and production environments.
4. Memory and Knowledge Base Poisoning
AI agents often use persistent memory, retrieval-augmented generation (RAG), and external knowledge bases to maintain context across tasks. Attackers can manipulate these information sources by inserting misleading data, malicious instructions, or fabricated records that influence future decisions.
Unlike attacks that affect a single interaction, memory poisoning can persist across multiple sessions. For example, an attacker could modify a knowledge base entry to make an unauthorized external service appear to be an approved destination for sensitive information. The agent might subsequently rely on that corrupted information when performing legitimate business operations, making the compromise difficult to identify through individual prompt inspections.
Agentic AI Security Best Practices
Securing agentic AI requires organizations to protect more than the underlying language models. Because AI agents can access sensitive information, interact with external tools, and execute tasks autonomously, security controls must address how agents are identified, what they can access, and how their activities are monitored.
The following best practices help organizations reduce agentic AI security risks while maintaining the flexibility and autonomy that make AI agents useful.
Assign Every AI Agent a Unique Identity
Each AI agent should have its own identifiable identity rather than sharing credentials or service accounts with other agents. Unique identities allow organizations to determine which agents are accessing systems, performing actions, or interacting with sensitive information.
Integrate agents into existing identity and access management (IAM) systems and maintain a centralized inventory of their owners, responsibilities, and permissions. When an agent is retired, compromised, or no longer needed, its access should be revoked promptly.
Use Secure Authentication for Agents and Connected Tools
AI agents frequently connect to enterprise applications, cloud services, databases, and external tools. Weak authentication or shared API keys can allow attackers to impersonate legitimate agents or gain unauthorized access to connected systems.
Use established authentication standards, such as OAuth, wherever supported, and avoid storing credentials directly in agent configurations or prompts. Organizations should also verify the identities of connected services and MCP servers before allowing agents to interact with them.
Control Delegated Access and Sensitive Actions
AI agents may perform tasks on behalf of human users or delegate work to other agents. Without clear authorization boundaries, agents could gain access to information or perform actions that the original user was not permitted to execute.
Ensure agents operate within the permissions granted by the requesting user and their assigned role. When tasks are delegated to other agents, permissions should remain limited to the work being performed. Sensitive operations should undergo additional authorization checks rather than relying on broad access granted at the beginning of a session.
Protect Agents Against Prompt Injection
Prompt injection occurs when attackers place malicious instructions in content that an AI agent processes, such as documents, websites, emails, or tool responses. These instructions may attempt to redirect an agent's behavior, expose sensitive information, or trigger unauthorized actions.
Organizations should treat externally retrieved content as untrusted and maintain clear boundaries between legitimate instructions and third-party data. Input validation, content filtering, and independent security checks can reduce the likelihood that malicious instructions influence agent behavior.
Verify MCP Servers and Third-Party Integrations
AI agents often rely on Model Context Protocol (MCP) servers, plugins, and external tools to interact with business systems. Compromised or poorly secured integrations can expose sensitive information, introduce malicious instructions, or provide attackers with additional entry points.
Establish an approval process for third-party tools before connecting them to production agents. Review their security practices, requested permissions, and data handling requirements. Organizations should also maintain an inventory of approved integrations and periodically reassess their security as tools and dependencies change.
What Is AI Agent Integration and How to Choose the Right Approach
AI agent integration connects agents to data and actions. Compare custom, iPaaS, MCP, and unified-API approaches, and the identity controls that keep them safe.
Require Human Approval for High-Risk Actions
Autonomous execution can improve efficiency, but some agent actions carry significant financial, operational, or security consequences. For example, an agent might delete business records, modify production infrastructure, or share confidential information with an external service.
Define which actions agents can perform independently and which require human approval. Routine tasks, such as retrieving information or generating reports, can generally proceed automatically. High-impact or irreversible operations should require explicit confirmation before execution, with sufficient context for reviewers to understand the proposed action.
Monitor Agent Behavior and Maintain Audit Logs
Traditional security monitoring may not provide sufficient visibility into autonomous agent activity, particularly when agents interact with multiple applications or delegate tasks to other agents. Without appropriate monitoring, security teams may struggle to identify suspicious behavior or investigate incidents.
Log significant agent activities, including tool usage, access to sensitive resources, permission changes, and executed operations. Integrate these records with existing security monitoring systems and establish alerts for unusual behavior, such as unexpected data transfers, repeated access failures, or actions outside an agent's normal responsibilities.
Test Agent Security Throughout Its Lifecycle
AI agents can behave unpredictably when exposed to malicious instructions, unexpected inputs, or changes in connected systems. Security testing during initial development is not sufficient because new integrations, permissions, and workflows can introduce additional vulnerabilities over time.
Conduct regular security assessments that simulate prompt injection, tool manipulation, data leakage, and unauthorized actions. Test agents before deployment and after significant configuration changes. Organizations should also establish procedures for disabling compromised agents, containing incidents, and restoring normal operations.
Enforce Identity and Authorization at the Agent Harness Level
Traditional identity and access management (IAM) controls authenticate users and services, but they may not evaluate every action an AI agent performs after authentication. The agent harness, which manages the execution loop between the model, tools, and external systems, provides an additional enforcement point. By integrating authorization into the harness, organizations can evaluate individual tool calls, shell commands, file operations, and API requests before they execute.
Harness-level security allows organizations to apply deterministic authorization policies to AI-generated actions, rather than relying exclusively on model instructions or network-level controls. For example, an agent might have permission to read a repository but not modify deployment configurations or execute production commands. Each action can be checked against the agent's identity, delegated authority, and applicable permissions before execution.
Ory Agent Security implements this approach by integrating identity and authorization controls directly into supported agent harnesses. It connects agent activity to existing identity infrastructure, supports fine-grained permission checks, and records the relationship between human users, agents, and sub-agents. This helps organizations enforce consistent security policies without introducing a separate identity stack specifically for AI agents.
Choose an IAM Platform That Scales with Agent and Non-Human Identity Growth
AI agents significantly increase the number of identities organizations must manage. Unlike human employees, agents can be created dynamically, operate for short periods, spawn sub-agents, and make frequent authorization requests across multiple systems. Research has reported ratios as high as 144 non-human identities for every human identity in certain enterprise environments, although this includes service accounts, API keys, and other machine identities, not just AI agents.
Organizations should evaluate whether their IAM infrastructure can handle large volumes of identity creation, token issuance, permission checks, and credential revocation without introducing latency or availability problems. Important capabilities include horizontally scalable authentication services, low-latency authorization, automated identity lifecycle management, and centralized policy enforcement across human and non-human identities. Existing IAM performance limitations can become much more severe as autonomous workloads multiply.
For example, Ory's OpenAI case study describes how OpenAI uses Ory Hydra as part of its identity infrastructure supporting a platform with more than 1.2 billion weekly active users. The case demonstrates the importance of scalable, resilient identity infrastructure for large AI services, although it concerns customer identity and authorization rather than a benchmark of simultaneous AI agent identities. Organizations deploying agentic AI should apply similar scalability requirements to their agent authentication and authorization systems.
Best IAM Solutions for Corporate Security
Compare the best IAM solutions for corporate security, from Okta and Entra ID to Ory and Keycloak, and learn how to evaluate the right fit for your stack.
Securing AI Agents at the Point of Execution with Ory Agent Security
Ory Agent Security brings visibility, identity, and control to AI agent behavior, helping organizations understand what their agents are doing, enforce policies at runtime, and scale agentic AI with confidence. It plugs into the agent harnesses, frameworks, and deployment methods teams already use, including Claude Code, Codex, Gemini CLI, CrewAI, LangChain, LangGraph, and Microsoft Agent Framework, through plugins, APIs, and SDKs. Ory Agent Security covers the entire agent security lifecycle across four interconnected capabilities: Observe, Enforce, Build, and Deploy.
Key capabilities of Ory Agent Security:
- Authenticated agent identities: Ory resolves each agent's identity inside the harness, whether it was started by a human, another agent, or a headless process. Every agent and sub-agent authenticates with its own credentials, and the delegation chain back to the user or upstream agent is recorded before any tool runs.
- Fine-grained authorization before execution: Before an agent action runs, Ory checks the requested tool against Ory Keto (Permissions). Shell commands, file writes, web fetches, MCP tools, and API calls are enforced through the same Zanzibar-style permission model used for human application access.
- MCP server governance: Ory adds OAuth 2.1 authorization for MCP servers, checking whether an agent session may use a given MCP server and optionally authorizing individual tools within that server.
- Flexible enforcement that fits your risk tolerance: Every agent action hits a decision point before it runs. Teams can observe first and enforce when ready, by category or down to the individual command, and cut off any agent instantly.
- Full observability and audit trails: Every permission check, tool call, and sub-agent start is recorded, including who started the session, which agent acted, what it attempted, and which policy decided. Records are exported through OpenTelemetry to your SIEM, and the delegation chain outlives the token so the trail holds even after credentials expire.
- Security built into agents and deployments: Embed identity, permissions, and guardrails into agents using APIs, SDKs, and plugins, then extend consistent security across growing agent deployments, environments, and workflows.
- Built on Ory's proven IAM ecosystem: Ory Agent Security extends Ory's identity and access management model to AI agents, with Kratos managing identities, Hydra issuing OAuth/OIDC tokens, and Keto providing fine-grained authorization.
Learn more about Ory Agent Security and start observing your agents' activity today.





