OpenAI Agent Security: OpenAI Agents SDK Security, Guardrails, and AgentKit Controls
OpenAI ships real guardrail primitives in the Agents SDK. It also documents, in its own reference, that input guardrails run only for the first agent in a chain. Most teams read past that line.
Direct answer
OpenAI agent security means keeping agents built on the OpenAI Agents SDK or AgentKit from causing damage with the tools and credentials you handed them. OpenAI provides genuine primitives: input, output, and tool guardrails with tripwires that halt a run, structured outputs that close freeform channels between steps, and a human approval mechanism that turns a sensitive tool call into a resumable interruption. OpenAI is also candid about the ceiling, stating in its safety guide that "even with these mitigations, agents won't be perfect and can still make mistakes or be tricked." Two documented scoping rules matter more than most teams realize. OpenAI's reference says plainly that "input guardrails run only for the first agent in the chain. Output guardrails run only for the agent that produces the final output," so in a handoff workflow the second and third agents receive unchecked input. And tool guardrails cover only tools built with the function_tool decorator, not handoffs and not hosted tools such as WebSearchTool or CodeInterpreterTool. Agentshield sits outside the agent process and closes both: inspection on every hop rather than the first one, and one policy and audit trail across every OpenAI agent you run.
Try it live
Watch Agentshield block an attack in real time.
Pick a scenario and drive the inspection lane yourself. No signup needed.
Run a request
Inspection lane
INSPECTINGPolicy trace
High-risk action held for approval
Audit trail
- § · → → →
The risk
The prototype used one agent and one guardrail, and it passed review. Then it became a triage agent that hands off to a billing agent that hands off to a refund agent with a payments tool attached. The guardrail is still there, still passing tests, and it has not inspected a single token since the first handoff. Nobody removed a control. The workflow simply grew past where the control applies.
How Agentshield handles it
Agentshield is stack-neutral and sits in the request and action path, so the Agents SDK, AgentKit workflows, and your MCP servers keep running exactly as written. OpenAI keeps enforcing its own in-process guardrails; we add the layer outside the process. Untrusted content is inspected before the agent acts on it at every hop, not only at the entry point, which is where the SDK scoping rules stop. Every tool call is checked against a permission scope attached to that agent rather than to the API key it happens to hold. Irreversible actions are held for a human even when the run is headless. Everything lands in one append-only record, including the calls that were denied.
The controls
The controls that secure the OpenAI Agents SDK services and AgentKit workflows your team ships to production.
What is OpenAI agent security?
OpenAI agent security covers three things that get discussed as one. The Agents SDK is the library your engineers use to build agents in Python or TypeScript, which then run on your infrastructure. AgentKit is the broader toolset OpenAI released for building, deploying, and optimizing those agents. Agent Builder was the visual workflow canvas, and it is on its way out: OpenAI states that it is deprecating Agent Builder and that the product is scheduled to shut down on November 30, 2026, with ChatKit as the recommended path forward.
The underlying problem is the one shared by every agent runtime. OpenAI defines it cleanly in its safety guide: a prompt injection happens when untrusted text or data enters an AI system, and malicious contents in that text or data attempt to override instructions to the AI. A support ticket becomes an instruction. So does a retrieved document, a web page, a tool result, or a tool description served by an MCP server somebody else operates.
What separates OpenAI from a framework that gives you nothing is that the guardrail primitives are real and well designed. Input guardrails validate what arrives. Output guardrails validate what leaves. Tool guardrails check function arguments and results. Tripwires halt the run rather than logging and continuing. Approvals turn a sensitive call into an interruption your application resolves. Used properly, that is a serious inner layer, and any honest assessment should say so.
The reason a runtime control layer still matters is not that the primitives are weak. It is that they are opt-in, written per agent by the developer building that agent, and scoped in ways that quietly stop applying as the workflow grows. The rest of this page is about exactly where they stop.
OpenAI Agents SDK security: what guardrails actually cover
This inventory comes from OpenAI's own SDK reference rather than from a marketing comparison. If you are evaluating the Agents SDK, assume you get all of this and nothing beyond it.
| Control | What it does | What it does not do |
|---|---|---|
| Input guardrails | Run validation on incoming user input, produce a GuardrailFunctionOutput, and raise InputGuardrailTripwireTriggered when the tripwire fires. Declared with the input_guardrail decorator | OpenAI's wording: they "only run if the agent is the first agent." An agent reached through a handoff never runs its own input guardrails |
| Output guardrails | Validate what the agent produced and raise OutputGuardrailTripwireTriggered on failure | Run only for the final agent in the chain. Intermediate agent output passes to the next agent unchecked, and they cannot run in parallel |
| Tool guardrails | Wrap FunctionTool instances to validate arguments before execution and results afterward. Can skip a call, replace the output, or raise a tripwire | Apply only to tools created with the function_tool decorator. Explicitly do not cover handoffs or hosted tools such as WebSearchTool and CodeInterpreterTool |
| Parallel execution (the default) | Runs the guardrail alongside the agent for the best latency | The agent may already have consumed tokens, and started work, before the guardrail cancels it. Blocking mode prevents that and is not the default |
| Human approval | A tool marked needsApproval returns an interruption plus resumable state instead of executing. State can be serialized and resumed later | Your application has to implement the approval surface, decide policy, and persist state. Nothing decides what is sensitive for you |
| Structured outputs | Enums, fixed schemas, and required fields between workflow nodes remove the freeform channels an attacker uses to smuggle instructions | Constrains the shape of what moves between steps, not whether the content inside a valid field is hostile |
| Model-level robustness | OpenAI states GPT-5 and GPT-5-mini show stronger robustness against jailbreaks and indirect prompt injections | A probabilistic property of the model, not a boundary. It reduces success rates and does not create an enforcement point |
OpenAI closes its safety guidance with a line worth quoting to anyone treating a vendor default as a finished control: even with these mitigations, agents will not be perfect and can still make mistakes or be tricked. The same guide notes that guardrails alone are not foolproof. That is the correct posture, and it is also the argument for a second layer.
Where OpenAI guardrails stop: the gaps that survive a correct setup
Every item below assumes you did the work properly. These are not misconfigurations. They are consequences of where the SDK draws its boundaries.
- Multi-agent handoffs bypass input guardrails entirely. This is the big one. OpenAI documents that input guardrails run only for the first agent in the chain. A triage agent that validates input and then hands off to a specialist agent has protected the front door and left every interior door open. The content that reaches agent two came from agent one, and it is trusted by construction. If your workflow has handoffs, read multi-agent security next.
- Hosted tools are outside tool guardrails. WebSearchTool and CodeInterpreterTool are exactly the tools that pull untrusted content into the context and execute code, and OpenAI states tool guardrails do not cover them. The tools with the widest blast radius are the ones the wrapping mechanism skips.
- Guardrails are opt-in, per agent, written by the developer. There is no default. An agent shipped without a guardrail decorator is an agent with no input validation, and nothing in code review announces its absence. The diff that removes one looks like a diff that removes a function.
- The default execution mode trades safety for latency. Parallel is the default, so the agent can consume tokens and begin work before the guardrail cancels it. For a read-only agent that is a cost question. For an agent with a tool that writes, it is a correctness question.
- Approvals need somebody to answer them. The interruption and resumable state model is well built, but it resolves to a human decision. In a scheduled job or a headless service there is nobody, so teams either drop needsApproval or auto-approve, and the control becomes decorative. See human in the loop AI agents.
- The agent inherits an API key, not an identity. An OpenAI agent acts with whatever credential the process holds. Two agents from different teams sharing a key are indistinguishable afterward, which makes attribution guesswork. See AI agent identity.
- Tripwire exceptions are not an audit trail. Raising an exception tells your application that a run stopped. It is not an append-only, per-decision record of which tool call was requested, whether policy allowed it, and which agent asked. That distinction is the whole of agent audit trail.
None of this argues against the Agents SDK. It argues for a control point where the individual developer's guardrail code is not the last word. The general form of that argument is on AI runtime security.
AgentKit and Agent Builder security, and what the shutdown means
AgentKit lowered the bar for building an agent, which is genuinely good and also means more agents exist than any security team was told about. The visual canvas in particular put workflow construction in the hands of people who do not read an SDK reference, and a misconfigured node is a security decision made by somebody who did not know they were making one.
OpenAI's own safety guidance for builders reduces to a short list, and it is worth following exactly:
- Never put untrusted variables in developer messages. Pass untrusted input through user messages instead, so it carries less authority. OpenAI calls this out first, and it is the single highest-leverage line in the guide. A developer message is closer to an instruction; a user message is closer to data.
- Define structured outputs between nodes. Enums, fixed schemas, and required field names remove the freeform text channel an attacker uses to smuggle instructions from one step to the next.
- Keep tool approvals on for MCP operations. OpenAI recommends human review for MCP actions specifically, which is a fair reflection of how little anyone can vouch for a third-party server.
- Sanitize inputs with guardrails. Redact personally identifiable information and screen for jailbreak attempts before the content reaches a privileged context.
- Run trace graders and evals. Score real agent actions rather than only final answers, so a workflow that reached the right output through a wrong tool call is still caught.
The deprecation matters for security planning, not just roadmaps. OpenAI states it is deprecating Agent Builder, with shutdown scheduled for November 30, 2026, and points users toward ChatKit. Migrations are where controls get dropped: a guardrail that existed as a node on a canvas has to be rewritten as code, and the version that ships under deadline pressure is usually the one without it. If you are migrating, inventory which workflows had approval nodes and guardrail nodes before you start, and treat restoring them as part of the migration rather than a follow-up ticket.
MCP connections deserve their own attention here. Tool descriptions are prompt input, and Invariant Labs documented tool poisoning in April 2025 as malicious instructions embedded within MCP tool descriptions that are invisible to users but visible to AI models. The Cloud Security Alliance followed in July 2026 with a study of more than 45 real-world MCP servers reporting attack success rates above 60 percent, peaking at 72.8 percent. CVE-2025-54136, rated CVSS 8.8, captured the structural version: approving a tool definition once does not bind the server to that definition later. Pin tool definitions by SHA-256 hash, keep the allowed server list in version control, and treat every server response as untrusted. The full treatment is on MCP server security, and the architecture that enforces it centrally is on MCP gateway.
OpenAI agent security best practices
This is the sequence we recommend to teams running Agents SDK services beyond a single prototype. The first five are OpenAI's own guidance and cost nothing but an afternoon.
- Put a guardrail on every agent, not the first one. Because input guardrails only run for the first agent in a chain, an agent reached by handoff needs its validation somewhere else: tool guardrails on its tools, or an inspection point outside the SDK. Assume any agent can become a downstream agent later.
- Switch critical guardrails to blocking mode. Parallel is the default and lets work begin before cancellation. Any agent holding a tool that writes, pays, sends, or deletes should validate before it starts, and pay the latency.
- Wrap hosted tools yourself. Tool guardrails skip WebSearchTool and CodeInterpreterTool. If you use them, treat everything they return as untrusted content and inspect it before it reaches the next step.
- Use user messages for untrusted input, always. Never interpolate a ticket body, a retrieved document, or a form field into a developer message. This is free and it removes a whole class of injection.
- Constrain the channels between steps. Structured outputs with enums and fixed schemas between nodes leave an attacker far less room than a free text handoff.
- Give each agent its own identity. Not native to the SDK, where an agent acts with whatever API key the process holds. Without it, you cannot scope permissions per agent or attribute an action afterward. See AI agent identity.
- Treat headless runs as a separate risk tier. Approvals assume a human. Scheduled jobs and background services need a narrower policy rather than the interactive one with approvals quietly disabled.
- Isolate execution. If the agent runs code or shell commands, put it in a container with no network route except a proxy you control, and never hand it a raw credential. See AI agent sandboxing and the step-by-step version in how to sandbox an AI agent.
- Run in observe mode first. Two weeks of watching what your agents actually call is worth more than a policy written from imagination, and it makes the switch to enforce uneventful. See tool permissions.
- Keep one trail across every agent. One append-only record covering Agents SDK services, AgentKit workflows, and anything built on another framework, so a question about last Thursday has one place to be answered.
Steps one through five are code changes you should make today whether or not you ever buy anything. Steps six through ten need a control point outside the agent process, because each is a property no per-agent decorator can guarantee across teams.
OpenAI vs Claude vs LangChain: which controls you get for free
Most teams run more than one framework, so the useful question is not which is safest in the abstract. It is which controls each one hands you, so you know what you are still on the hook for.
| Property | OpenAI Agents SDK | Claude Code and Agent SDK | LangChain and LangGraph |
|---|---|---|---|
| Default permission posture | No default gate. Tools are available once passed in | Read-only until approved, fail-closed on unmatched commands | No default gate |
| Injection handling on untrusted content | Guardrail primitives exist and are opt-in. First agent only | Isolated context window for web fetch, summarized search results | None by default. Middleware is opt-in per agent |
| Built-in approval mechanism | Yes. needsApproval with resumable state, you implement the surface | Yes. Interactive prompts, disabled in headless mode | Interrupts in LangGraph, you implement the surface |
| Execution isolation | Your own containerization. Nothing built in | Built-in OS-level bash sandbox plus documented container and VM paths | Your own containerization. Nothing built in |
| Coverage across a multi-step workflow | Documented gap: guardrails scope to first and final agent | Controls apply per session, not per workflow hop | Whatever you wrote, per node |
| Per-agent identity | Not native. Inherits the API key | Not native. Inherits the launching user or service account | Not native. Usually one shared service account |
| Fleet-wide policy | None | Managed settings help, still per-repository in practice | None |
| Independent audit record | Traces and evals, which are developer tooling | Usage telemetry, full audit logging in hosted cloud sessions | Application logs |
Claude wins the top half of that table on defaults, and it is worth choosing on those grounds. OpenAI has the better composable primitives, particularly tool guardrails and the approval state model, and beats LangChain comfortably. The bottom three rows are identical for all three, and they are the rows a security owner gets judged on. That is the gap we fill, and we fill it the same way regardless of framework, which is the point of being stack-neutral. Framework-specific notes are on Claude agent security and LangChain security.
FAQ
Common questions about openai agent security.
Are OpenAI agents secure?
They can be, with work. The Agents SDK ships real primitives: input, output, and tool guardrails with tripwires, structured outputs between steps, and a human approval mechanism. All of them are opt-in and written per agent. OpenAI states in its own safety guide that even with these mitigations, agents will not be perfect and can still be tricked.
How do OpenAI Agents SDK guardrails work?
A guardrail function runs alongside or before the agent and returns a GuardrailFunctionOutput. If its tripwire is triggered, the SDK raises an exception and halts the run. Input guardrails check user input, output guardrails check the final response, and tool guardrails validate a function tool arguments and results before and after execution.
Do OpenAI guardrails run on every agent in a workflow?
No, and this is the most commonly missed detail. OpenAI documents that input guardrails run only for the first agent in the chain and output guardrails run only for the agent producing the final output. In a handoff workflow, downstream agents receive input that no input guardrail inspected.
Do tool guardrails cover hosted tools like WebSearchTool?
No. Tool guardrails apply only to tools created with the function_tool decorator. OpenAI states they do not cover handoffs or hosted tools such as WebSearchTool and CodeInterpreterTool. Those are the tools that pull in untrusted content and execute code, so treat their results as unvalidated and inspect them separately.
What are the main OpenAI agent security risks?
Four dominate. Prompt injection arriving through tickets, retrieved documents, tool results, or MCP servers. Guardrail scoping, where handoffs and hosted tools fall outside coverage. Shared API keys instead of per-agent identity, which prevents scoping and attribution. And headless runs where approval prompts have nobody to answer them.
Is OpenAI Agent Builder being discontinued?
Yes. OpenAI states it is deprecating Agent Builder and that the product is scheduled to shut down on November 30, 2026, with ChatKit as the recommended alternative. Existing users can continue during the transition window. Treat the migration as a security event: inventory approval and guardrail nodes first so they get rebuilt rather than dropped.
How do I prevent prompt injection in OpenAI agents?
Start with OpenAI own guidance: never interpolate untrusted text into developer messages, pass it through user messages instead, and define structured outputs between workflow steps so there is no freeform channel to smuggle instructions through. Then add input guardrails, keep approvals on for MCP tools, and inspect content at every hop rather than only the first.
Should I use blocking or parallel guardrails?
Parallel is the default and gives the best latency, but the agent can consume tokens and begin work before the guardrail cancels it. Use blocking mode for any agent holding a tool that writes, pays, sends, or deletes, where starting work on malicious input is itself the harm. Parallel is reasonable for read-only agents.
Is the OpenAI Agents SDK more secure than LangChain?
On built-in primitives, yes. OpenAI ships guardrails with tripwires, tool-level validation, and a resumable approval model, where LangChain leaves nearly all of it to you. Neither provides per-agent identity, fleet-wide policy, or an independent audit record, and Claude Code beats both on default permission posture.
Does Agentshield replace OpenAI guardrails?
No, and you should keep them. OpenAI in-process guardrails are the inner layer and they are well designed. Agentshield adds the outer layer: inspection at every workflow hop rather than the first agent only, coverage for hosted tools the SDK skips, approval gates that survive headless runs, per-agent permission scopes, and one audit trail across every framework you run.
More use cases