|
| 1 | +--- |
| 2 | +title: Codex Coding Agent |
| 3 | +description: Run OpenAI Codex in an isolated repository sandbox to produce an implementation plan or create a pull request. |
| 4 | +--- |
| 5 | + |
| 6 | +import { Callout } from 'fumadocs-ui/components/callout' |
| 7 | +import { BlockPreview } from '@/components/workflow-preview' |
| 8 | + |
| 9 | +The **Codex Coding Agent** block runs a pinned OpenAI Codex CLI in an isolated E2B or Daytona sandbox. A logical agent can keep its native Codex thread and repository checkout across multiple blocks or loop rounds, inspect a GitHub repository and return a plan, or implement a task and maintain a pull request. |
| 10 | + |
| 11 | +<BlockPreview type="codex" /> |
| 12 | + |
| 13 | +## Modes |
| 14 | + |
| 15 | +### Plan |
| 16 | + |
| 17 | +Plan clones the repository into a disposable checkout, removes the authenticated Git remote, and lets Codex read files, search, and run checks. It returns a Markdown plan and performs no commit, push, pull request, or other GitHub write. |
| 18 | + |
| 19 | +Later turns for the same agent continue the native Codex thread in the same checkout, so one step can investigate and another can refine or challenge the plan without rebuilding context. |
| 20 | + |
| 21 | +### Create PR |
| 22 | + |
| 23 | +Create PR clones the selected base branch, asks Codex to edit the checkout, and waits for a successful `turn.completed` event. Sim then performs the credentialed delivery steps separately: |
| 24 | + |
| 25 | +1. Verify that repository-local Git configuration did not change during the Codex turn. |
| 26 | +2. Stage and commit the changes without an OpenAI or GitHub credential in scope. |
| 27 | +3. Capture the changed files and a bounded unified diff. |
| 28 | +4. Push the new branch with the GitHub token. |
| 29 | +5. Create the pull request through Sim's GitHub integration. |
| 30 | + |
| 31 | +If Codex makes no changes, the block returns successfully without pushing a branch or opening a pull request. |
| 32 | + |
| 33 | +Later turns for the same agent continue editing the same local branch. Sim pushes the new commit to the existing branch and returns the existing pull request instead of creating another one. |
| 34 | + |
| 35 | +## Agent instances and session reuse |
| 36 | + |
| 37 | +Each block is its own agent by default. Repeating that block in a loop continues the same sandbox, checkout, and native Codex thread. |
| 38 | + |
| 39 | +Choose an existing **Agent** when multiple Codex blocks should address one logical agent. The picker uses friendly labels such as Agent 1 and Agent 2; internal IDs are generated and managed automatically. Steps with the same agent share the instance and their turns run serially. Different agents create isolated instances and may run concurrently. Stable runtime configuration belongs to that logical Agent, so every step resolves the same mode, model, repository, and base branch. |
| 40 | + |
| 41 | +Choose **New agent** to split a step into an independent sandbox and Codex thread. Copying a block also creates an independent agent by default. When several blocks that share an agent are copied together, the copied group keeps sharing with itself but not with the original group. |
| 42 | + |
| 43 | +Agent instances are execution-scoped: Sim closes all of them when the uninterrupted workflow execution succeeds, fails, pauses, or is cancelled. A later independent workflow execution starts fresh. Durable reuse across independent executions requires a persistent runner and is not inferred from a thread ID alone, because Codex resume also requires its local rollout state. |
| 44 | + |
| 45 | +## Configuration |
| 46 | + |
| 47 | +Codex configuration is a sparse overlay, similar to a Kustomize patch. Resolution runs in this order: |
| 48 | + |
| 49 | +1. Workspace profile |
| 50 | +2. Workflow defaults |
| 51 | +3. Agent settings |
| 52 | +4. Step override |
| 53 | + |
| 54 | +Only keys explicitly set at a layer are stored there; missing keys inherit. A Workspace change therefore reaches every Workflow, Agent, and Step that has not overridden that field. Sim freezes the resolved layers for an uninterrupted execution, so a settings edit cannot change an Agent halfway through a run. |
| 55 | + |
| 56 | +- **Workspace profile** — shared defaults managed under **Settings → Codex**. |
| 57 | +- **Workflow defaults / Agent settings** — opened from **Configure** below the Agent picker. |
| 58 | +- **Task** — what Codex should plan or implement. |
| 59 | +- **Agent** — choose a workflow agent to reuse, or create a new independent one. Sim manages its internal ID. |
| 60 | +- **Mode / Model / Repository / Base Branch / Agent Shell Network** — stable layered settings, normally configured on the Agent or inherited from the Workflow and Workspace. |
| 61 | +- **OpenAI API Key** — your key, entered on the block or stored as OpenAI BYOK. Sim never substitutes a hosted model key for this block. |
| 62 | +- **GitHub Token** — clone access for Plan; clone, push, and pull-request write access for Create PR. |
| 63 | +- **Reasoning Effort (Step Override)** *(advanced)* — `low`, `medium`, `high`, or `xhigh`; leave blank to inherit the Agent/Workflow/Workspace value. |
| 64 | +- **Branch Name / Draft / PR Title / PR Body** *(advanced)* — optional step-local pull-request delivery settings, used in Create PR mode. |
| 65 | + |
| 66 | +## Isolation |
| 67 | + |
| 68 | +Every agent instance receives a private `CODEX_HOME`. Its rollout files are retained only while that workflow execution is active so later turns can use `codex exec resume`. The runtime ignores user config and execpolicy rules, disables hooks, plugins, apps, collaboration, skill discovery, and persisted goals, and runs with the `workspace-write` sandbox. Headless Codex runs never request approval. The shell environment is restricted so model-generated commands do not inherit `OPENAI_API_KEY`. |
| 69 | + |
| 70 | +The GitHub token is present only during clone and push or in the host-side pull-request API call. It is never placed in the Codex process environment. |
| 71 | + |
| 72 | +<Callout type="warn"> |
| 73 | + Repository contents are untrusted instructions. Keep **Agent Shell Network** off unless the task needs it, use narrowly scoped credentials, and review every generated pull request before merging. |
| 74 | +</Callout> |
| 75 | + |
| 76 | +The MVP does not resume Codex threads across independent workflow executions and does not expose Sim tools, MCP servers, plugins, hooks, or mid-turn human approval. Those capabilities require the persistent app-server runner planned for a later phase. |
| 77 | + |
| 78 | +## Outputs |
| 79 | + |
| 80 | +| Output | Description | |
| 81 | +| --- | --- | |
| 82 | +| `<codex.content>` | Final Codex message or Markdown plan | |
| 83 | +| `<codex.model>` | Model selected for the run | |
| 84 | +| `<codex.runStatus>` | Terminal status (`completed` for returned outputs; failures fail the block) | |
| 85 | +| `<codex.agentId>` | Resolved logical agent instance ID | |
| 86 | +| `<codex.sessionReused>` | Whether this turn continued an existing instance | |
| 87 | +| `<codex.turnNumber>` | One-based turn number within the instance | |
| 88 | +| `<codex.threadId>` | Native Codex thread ID resumed by later turns in this execution | |
| 89 | +| `<codex.commands>` | Bounded command, patch, and tool summaries | |
| 90 | +| `<codex.changedFiles>` | Files changed in Create PR mode | |
| 91 | +| `<codex.diff>` | Bounded unified diff in Create PR mode | |
| 92 | +| `<codex.branch>` | Branch pushed in Create PR mode | |
| 93 | +| `<codex.prUrl>` | Pull request URL in Create PR mode | |
| 94 | +| `<codex.tokens>` | Input, cache, output, and reasoning token counts | |
| 95 | +| `<codex.cost>` | Sim-attributed model cost; zero because this block is BYOK-only | |
| 96 | +| `<codex.providerTiming>` | Start time, end time, and duration | |
| 97 | + |
| 98 | +## Self-hosted setup |
| 99 | + |
| 100 | +Build the dedicated image after setting the provider API key: |
| 101 | + |
| 102 | +```bash |
| 103 | +bun run apps/sim/scripts/build-codex-e2b-template.ts --name sim-codex |
| 104 | +bun run apps/sim/scripts/build-codex-daytona-snapshot.ts --name sim-codex:<tag> |
| 105 | +``` |
| 106 | + |
| 107 | +For E2B, set `SANDBOX_PROVIDER=e2b`, `E2B_API_KEY`, and `E2B_CODEX_TEMPLATE_ID`. For Daytona, set `SANDBOX_PROVIDER=daytona`, `DAYTONA_API_KEY`, and `DAYTONA_CODEX_SNAPSHOT_ID`. |
| 108 | + |
| 109 | +The image pins `@openai/codex@0.146.0`. Upgrade the package contract, JSONL fixtures, parser tests, and both provider images together. |
0 commit comments