Agentshield

OpenAI Agents vs LangChain: Agents SDK Security Compared for Production

Marcus Feld, Platform·Aug 11, 2026·9 min read

Try it live

Watch Agentshield block an attack in real time.

Pick a scenario and drive the inspection lane yourself. No signup needed.

Threat Console
12,408 injections blocked this week

Run a request

Inspection lane

INSPECTING
untrusted input

Policy trace

High-risk action held for approval

Audit trail

On security specifically, the OpenAI Agents SDK is the stronger starting point. It ships guardrail primitives with real enforcement semantics: input, output, and tool guardrails that raise a tripwire and halt the run, structured outputs that close the freeform channels between workflow steps, and a human approval model that turns a sensitive tool call into a resumable interruption. LangChain gives you middleware hooks and leaves the policy, the enforcement, and the failure behavior to you. If you are choosing today and security is the deciding factor, pick the Agents SDK.

That verdict comes with a caveat large enough to change your architecture. OpenAI documents that input guardrails run only for the first agent in a chain and output guardrails run only for the agent producing the final output. The moment your workflow grows a handoff, which is the normal way these systems evolve, your validation stops covering most of it. Nobody removes a control. The workflow simply grows past where the control applies.

OpenAI Agents SDK vs LangChain: the security comparison

This table covers what each framework gives you without writing custom infrastructure. Both are capable frameworks and this is not a verdict on either as a whole, only on the controls that arrive in the box.

Security propertyOpenAI Agents SDKLangChain and LangGraph
Input validationInput guardrails with tripwires that halt the run. Opt-in per agent, first agent onlyNo built-in concept. Middleware you write, invoked where you invoke it
Output validationOutput guardrails, final agent only, no parallel executionOutput parsers for structure. Nothing that enforces a safety policy
Tool-level checksTool guardrails validate arguments before and results after execution. Can skip a call or replace outputNone built in. You wrap the tool yourself
Human approvalYes. A tool marked needsApproval returns an interruption plus serializable resumable stateLangGraph interrupts give you the pause. You build the approval surface and the policy
Failure behaviorFail closed. A tripwire raises an exception and stops executionWhatever your code does. Easy to log and continue by accident
Structured handoffsEnums and fixed schemas between nodes are first-class and recommendedSupported, not the default path, and rarely used to constrain injection
Public CVE historyNo comparable public wave to dateA 2025 to 2026 wave across separately versioned packages, including a CVSS 9.3
Execution isolationNone built in. Your containersNone built in. Your containers
Per-agent identityNone. Inherits the API key the process holdsNone. Usually one shared service account
Independent audit recordTraces and evals, which are developer toolingApplication logs

The top seven rows are where OpenAI wins, and it wins them clearly. The bottom three are identical, and they are the rows a security owner answers for.

Does the OpenAI Agents SDK protect against prompt injection?

Partly, and better than LangChain does by default. OpenAI defines the problem precisely 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. Its recommended defenses are practical and mostly free. Do not interpolate untrusted text into developer messages, pass it through user messages instead so it carries less authority. Define structured outputs between steps so there is no freeform channel to smuggle instructions through. Keep approvals on for MCP operations. Screen inputs for jailbreak attempts and redact personal data before it reaches a privileged context.

OpenAI also publishes the ceiling, in a sentence most vendors would cut: even with these mitigations, agents will not be perfect and can still make mistakes or be tricked. The same guidance notes that guardrails alone are not foolproof. Treat that as the design input it is. A guardrail lowers the success rate of an attack; it does not create a boundary an attacker cannot cross.

LangChain is blunter still. Its security policy tells you to limit permissions, anticipate misuse, and use defense in depth, and states plainly: "No security technique is perfect." Both vendors are being honest. Neither is promising you a solved problem.

Where OpenAI guardrails stop covering your workflow

Three documented scoping rules matter more than anything else on this page, because each one silently reduces coverage as a system matures.

  • Handoffs skip input guardrails. Input guardrails run only for the first agent in the chain. A triage agent that validates input and hands off to a billing agent has protected the front door only. Whatever reaches agent two is trusted by construction, and agent two is often the one holding the tool that moves money. The pattern-level version of this problem is on multi-agent security.
  • Hosted tools skip tool guardrails. Tool guardrails apply only to tools built with the function_tool decorator. OpenAI states they do not cover handoffs or hosted tools such as WebSearchTool and CodeInterpreterTool. Those two pull untrusted content into context and execute code respectively, so the widest-blast-radius tools are the ones the wrapping mechanism skips.
  • Parallel is the default. Guardrails run alongside the agent for latency, which means the agent can consume tokens and begin work before the guardrail cancels it. For a read-only agent that is a billing question. For an agent with a write tool, starting work on malicious input is the harm itself. Switch anything that writes, pays, sends, or deletes to blocking mode.

None of these are bugs. They are reasonable boundaries for a library that cannot know your topology. They become risks at the point where the topology grows and nobody re-reads the reference.

What about AgentKit and Agent Builder?

AgentKit made agent building dramatically more accessible, which also means more agents exist than any security team was told about. Agent Builder, the visual canvas, is being retired: OpenAI states it is deprecating the product and that it is scheduled to shut down on November 30, 2026, with ChatKit as the recommended path.

Plan that migration as a security event rather than a plumbing task. A guardrail that existed as a node on a canvas has to be rebuilt as code, and the version shipped under a deadline is usually the one without it. Inventory which workflows currently have guardrail nodes and approval nodes before you start moving anything, and treat restoring each one as part of the migration rather than a follow-up ticket nobody picks up.

Which is more secure for a production agent?

For a single-agent service with well-defined tools, the Agents SDK, comfortably. You get validation, tripwires, tool-level checks, and an approval model without building any of it, and the failure mode is closed rather than whatever your exception handler happens to do.

For a multi-agent workflow with handoffs, the honest answer is that the gap narrows sharply, because the SDK feature you would be choosing it for stops applying past the first agent. You end up writing coverage for hops two and three yourself, which is roughly the position LangChain starts you in. Knowing that before you design the topology is worth more than the framework choice.

For anything running code or shell commands, neither framework helps. Both leave isolation entirely to you, and it is the control that matters most for that class of agent. Framework-specific breakdowns are on OpenAI agent security and LangChain security. If you are also running coding agents, Claude agent security covers the one runtime that does ship isolation by default.

The three gaps neither framework closes

These are the same in both columns, and they are the ones that turn into audit findings.

  1. No per-agent identity. An agent acts with whatever API key or service account the process holds. Two agents from different teams sharing a credential are indistinguishable in any downstream log, which makes both scoping and after-the-fact attribution guesswork. See AI agent identity.
  2. No fleet-wide policy. Guardrails are code in a repository, written per agent by whoever built it. There is no place to answer what all of your agents are collectively allowed to do, and no way to change it in one action. A pull request that deletes a guardrail decorator looks like a pull request that deletes a function.
  3. No independent audit record. Traces, evals, and application logs are developer tooling. They are not an append-only, per-decision record of which tool call was requested, whether policy allowed it, and which agent asked, which is what an auditor means by the phrase. See agent audit trail.

The PII question sits underneath all three. Both vendors recommend redacting personal data before it reaches a privileged context, which quietly assumes you know where personal data lives in the first place. Most teams discover during their first deletion request that the map is less complete than they assumed, and an agent with broad read access is very good at finding the copies nobody documented. Scope agent read access on the assumption that the inventory is incomplete, because it usually is.

What to do this week

Five changes, in order, whichever framework you picked. The first three are free and take an afternoon.

  1. Move untrusted input out of developer messages and into user messages. This removes an entire class of injection and costs one refactor.
  2. Switch guardrails to blocking mode on every agent holding a tool that writes, pays, sends, or deletes.
  3. Add validation to agents reached by handoff, since their own input guardrails will not run. Tool guardrails on their tools are the cheapest place to put it.
  4. Wrap hosted tools yourself, and treat everything WebSearchTool and CodeInterpreterTool return as untrusted content.
  5. Run in observe mode before you enforce. Two weeks of watching what your agents actually call beats a policy written from imagination, and it makes the switch uneventful. See tool permissions.

Steps one through four are framework work you should do regardless. The three gaps in the previous section are not framework work, because no per-agent decorator can guarantee a property across teams. That is the layer AI runtime security describes, and it is why we built Agentshield to sit outside the agent process rather than inside anyone's SDK.

See the firewall block an attack live.

Drive the Threat Console and watch a real prompt injection get stopped, then put Agentshield in front of your own agents.

Open the console