Building & Deploying Secure AI Agents: From Tool Call to Production | Ory
Technical Deep Dive: Building and Deploying Secure AI Agents
A technical deep dive into Ory Agent Security Build and Deploy, from SDK interception and delegation to runtime identity, deployment packages, CI automation, and revocation.
Securing AI Agents at Two Different Layers
Securing an AI agent requires control at two different layers. The first is inside the application: every relevant tool call must cross a point where identity-aware policy can make a decision. The second is in the runtime: the deployed agent needs its own noninteractive identity, a safe way to receive credentials, and an operational lifecycle that includes activation, rotation, and revocation.
Build and Deploy
Ory Agent Security calls these product surfaces Build and Deploy.
- Build connects an agent harness or SDK to authentication, delegation, permission checks, and activity reporting.
- Deploy registers a runtime identity, validates a supported agent-and-runtime combination, and packages the Agent Security configuration for an operator-controlled environment.
Build Starts at the Tool Boundary
Agents turn model output into effects through tools. A tool might read a file, execute a shell command, query a database, call an API, invoke an MCP server, or start another agent. That dispatch point is where Ory Agent Security can make a useful authorization decision: after the agent has selected an action, but before the action executes.
Harness Plugins
A harness plugin is appropriate when an existing agent product owns the control loop. Ory Agent Plugins integrate with the lifecycle primitives exposed by coding harnesses such as Claude Code, Codex, Gemini CLI, Cursor, OpenCode, and others.
Agent SDK Integrations
An SDK integration is appropriate when developers own the application and its tool map. Ory publishes integrations across TypeScript and Python for frameworks including Vercel AI SDK, Anthropic Claude Agent SDK, Mastra, Cloudflare Agents, OpenRouter Agent SDK, Pi, LangChain and LangGraph, OpenAI Agents SDK, Pydantic AI, CrewAI, LlamaIndex, Google ADK, AWS Strands, and others.
The Common Agent Security Lifecycle
The TypeScript and Python integrations share a common logical sequence.
1. Start or Resolve the Session
An interactive harness session can authenticate the human user and enroll or resolve the machine runtime. A headless deployed agent instead starts from its Deploy-issued runtime proof and calls the runtime-context endpoint to obtain server-owned identity and lineage data.
2. Establish Delegation
The root relationship answers: which person or automation sponsor is responsible for this agent? When supported sub-agents are created, Ory can issue each direct child a separate runtime identity and record immutable parentage.
3. Check Permission Before Execution
Before the tool runs, the adapter sends a bounded permission request for the authenticated principal and target. Agent and shell tools are generally usable by default unless an explicit block applies.
4. Record Outcomes
Authorization is only half of an audit trail. After execution, the adapter records completion and, where the framework lifecycle exposes the required hook, failure.
Thin Adapters, Shared Security Cores
Ory's integration architecture keeps framework packages thin. Shared TypeScript and Python cores implement difficult, reusable behavior such as session initialization, agent enrollment, permission checks, and audit activity.
From Local Build to Headless Runtime
During development, an interactive agent can use a browser login to associate a person with the session. A production workload cannot depend on a developer being present to complete that flow. It also should not carry a copied human OAuth token.
A Catalog, Not a Matrix of Assumptions
Agent frameworks and execution environments evolve independently. Supporting an SDK does not automatically mean every runtime and credential method is valid for it.
The Declarative Deployment Workflow
The standalone ory-agent CLI supports a manifest-driven workflow.
api_version: agent-security.ory.sh/v1
kind: AgentDeployment
name: support-agent
agent_type: openai-agents
runtime_id: e2b
package_recipe: e2b-sandbox
package_recipe_version: v1
credential_method: talos_api_key
Runtime Credentials and Trust Boundaries
Deploy supports three runtime authentication patterns, subject to the selected catalog entry.
Talos API Keys
Agent Security can issue an actor-bound Talos key scoped to Agent Security runtime calls. The one-time secret is returned to the deployment flow.
Customer-managed X.509 mTLS
For supported administrative deployments, an operator can register the exact SHA-256 fingerprint of a customer-managed leaf certificate.
SPIFFE X.509 SVIDs
In a supported SPIFFE deployment, the operator supplies the workload identity and operates the SPIFFE control plane.
What is in a Deployment Package?
An Agent deployment package is the bridge between registration and the operator's runtime. It contains an immutable manifest, protected environment material, operator guidance, and target-specific configuration.
Safe Handoff to an Operator-controlled Runtime
The ory-agent deployment run flow demonstrates the intended credential boundary.
Example: OpenAI Agents SDK on E2B
An ephemeral sandbox makes the Build/Deploy split concrete. The operator builds and pins a credential-free E2B template.
Example: an Agent on Kubernetes with SPIFFE
For a long-running Kubernetes agent, Build remains framework-specific: the application connects its complete tool map to the appropriate Ory adapter.
CI/CD Without a Broad Human Credential
Deployment automation should not rely on a developer's long-lived login token. Agent Security supports a dedicated project-scoped deployment automation key.
Activation, Verification, and Revocation
Creation is not proof that a workload is functioning. Agent Security distinguishes package issuance from runtime activation.
A Production Checklist
Before deploying a secured agent, verify the complete path:
- Every executable tool crosses the selected harness or SDK boundary.
- Allowed and denied calls have both been tested in Observe.
- Enforce behavior uses a real framework or harness block signal.
- The agent type, runtime, recipe, version, and credential method pass a live catalog plan.
One Security Model from Code to Runtime
Build and Deploy address different failure modes. Together, they establish a continuous chain of operation.