Overview
The Codex bridge wraps OpenAI’scodex CLI, providing access to Codex’s code-generation capabilities through Agent-Ctrl’s unified API. Codex is particularly well-suited when you need fine-grained sandbox controls over filesystem and network access, image-based prompts, and automatic approval workflows.
The bridge is implemented by CodexBridge and configured through CodexBridgeBuilder. Access the builder through the AgentCtrl facade:
Basic Usage
Sandbox Modes
Codex provides three sandbox modes that control what filesystem and network access the agent has during execution. These are managed through theSandboxMode enum:
| Mode | Filesystem | Network | CLI Value | Use Case |
|---|---|---|---|---|
SandboxMode::ReadOnly | Read-only | No | read-only | Safe analysis, code review, reading files without modification |
SandboxMode::WorkspaceWrite | Write access to workspace | No | workspace-write | Code generation, refactoring, test writing |
SandboxMode::DangerFullAccess | Full access | Yes | danger-full-access | Tasks requiring network access or system-wide file operations |
Disabling the Sandbox
ThedisableSandbox() method is a shorthand for withSandbox(SandboxMode::DangerFullAccess):
Approval Modes
Codex supports two approval configuration methods that control how the agent handles permission requests.Full Auto Mode
fullAuto() enables automatic approval with workspace-write sandbox access. This is the default configuration (true), making it suitable for headless execution:
Dangerous Bypass
dangerouslyBypass() skips all approval prompts and all sandbox restrictions. This is the most permissive mode and should be used only when you fully trust the agent and the execution environment:
Warning: This mode disables all safety guardrails. The agent can execute arbitrary commands, modify any file, and access the network without restriction.
Git Repository Check
By default, Codex requires the working directory to be inside a Git repository. UseskipGitRepoCheck() to bypass this requirement when working with non-Git directories:
Image Input
Codex supports image attachments, allowing the agent to analyze visual content alongside text prompts. UsewithImages() to attach one or more image files:
Additional Directories
UsewithAdditionalDirs() to grant the agent write access to directories beyond the working directory:
Streaming with Codex
Codex streams output as JSON Lines containing item events (started, completed), turn events, thread events, and error events. The bridge normalizes these into the standard callback API:Tool Call Normalization
Codex produces several item types that are normalized intoToolCall objects:
| Codex Item Type | Normalized Tool Name | Input Structure |
|---|---|---|
CommandExecution | 'bash' | ['command' => '...'] |
FileChange | 'file_change' | ['path' => '...', 'action' => '...'] |
McpToolCall | Original tool name | Original arguments |
WebSearch | 'web_search' | ['query' => '...'] |
PlanUpdate | 'plan_update' | [] |
Reasoning | 'reasoning' | [] |
UnknownItem | Original item type | [] |
isError flag is set when the item has an error status (error, failed, cancelled) or when a CommandExecution has a non-zero exit code.
Working with Tool Calls
Session Management
Codex uses thread-based conversations. Agent-Ctrl normalizes the thread ID into anAgentSessionId:
Data Availability
| Data Point | Available | Notes |
|---|---|---|
| Text output | Yes | Extracted from AgentMessage items |
| Tool calls | Yes | Normalized from all item types (see table above) |
| Session ID | Yes | Normalized from Codex thread ID |
| Token usage | Yes | Input tokens, output tokens, cached input tokens |
| Cost | No | Codex CLI does not expose cost data |
| Parse diagnostics | Yes | Malformed JSON line counts and samples |
Token Usage
When Codex exposes usage statistics, they are converted into the unifiedTokenUsage DTO: