Skip to content

feat: implement Codex as sandbox external agent (#2422) - #2536

Merged
yannickmonney merged 3 commits into
mainfrom
feat/codex-external-agent-2422
Jul 7, 2026
Merged

yannickmonney merged 3 commits into
mainfrom
feat/codex-external-agent-2422

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Summary

  • Add agentKind: codex as a first-class external sandbox runtime alongside Claude Code, Cursor, and Hermes (Claude Code parity for the chat composer path).
  • Ship a Codex adapter (buildExec + --json JSONL parser) under services/platform/lib/agent-adapters/codex/, wired through the capability-based turn lifecycle, schema, agent editor, model selector, readiness, docs (en/de/fr), locales, and a shipped builtin-configs/agents/chat/codex.json composer agent.
  • Sandbox image installs the pinned @openai/[email protected]; no wrapper needed — the CLI's native JSONL is the parse contract.

Design decisions (each verified against the pinned codex-cli 0.142.5 binary locally)

  • Prompt over stdin, never argv — codex exec … - reads the prompt from stdin; leading-dash prompts can't parse as flags and argv never leaks the prompt.
  • Everything on -c overrides — codex exec resume is a subcommand with a narrower flag surface (no -s/-C/--add-dir), so posture (approval_policy="never", sandbox_mode="danger-full-access"), provider, web-search denial, developer_instructions, and MCP servers all ride -c, identical for fresh and resumed turns.
  • Managed = gateway Responses API — wire_api = "chat" was REMOVED in this Codex version (startup error); the adapter defines model_providers.tale with base_url = <gateway>/openai/v1, wire_api = "responses", and env_key = "TALE_GATEWAY_TOKEN" so the session virtual key rides env, never argv. Verified live against a mock Responses endpoint: Authorization: Bearer <VK>, full turn incl. real command execution.
  • systemPromptAppend → developer_instructions — lands verbatim as a developer message in the request (verified in captured request bodies); never dropped.
  • Managed denies native web tools — web_search defaults to LIVE under a full-access sandbox, so managed runs set web_search="disabled" unless nativeWebTools === true; BYO keeps native tools. The interactive request_user_input tool needs no denial: codex exec auto-declines it ("unavailable in Default mode", verified) — no hang, the agent asks in prose.
  • Resume — codex exec resume <thread_id> verified end-to-end: same thread_id re-emitted, prior turns present in the next request; CODEX_HOME=/user/.runtime/home/.codex keeps the session store on the /user volume.
  • BYO dialect — credentialPolicy.byoModelIdSource: 'vendor-native' (BYO talks to OpenAI's own API via a custom provider + OPENAI_API_KEY env_key — no codex login state); the shipped openai/gpt-5.5(-pro) catalog entries now carry nativeModelId so catalog refs translate correctly.
  • MCP secrets off argv — integration bridge env goes through mcp_servers.<id>.env_vars whitelist (verified: Codex forwards only whitelisted vars to MCP stdio servers).
  • Usage — tokens from turn.completed only; zero-token turns emit no usage event. No fallback-model claims anywhere: Codex has no availability chain and the docs say so.
  • Hardening found during the sweep: steer_delivery.ts and recover_external_agent_turns.ts coerced stored agent kinds with === 'cursor' ? … : 'claude-code' ternaries, which misroute every newer runtime (Hermes today, Codex now) — replaced with a PRODUCT_AGENT_SLUGS membership guard (isProductAgentSlug).
  • Parser fixture is captured from a real codex exec --json run (sanitized); other item shapes are tested inline from the @openai/codex-sdk typings, which version with the CLI.

Test plan

  • vitest --project server lib/agent-adapters (101 tests, incl. new Codex adapter/parse suites + chunk-split fixture replay)
  • Schema accepts agentKind: codex (managed + byo); invalid-kind guard updated
  • Full platform suite vitest --project server --project pii — 74 860 passed
  • UI tests (model-selector, chat components, dashboard routes) — 339 passed
  • bun run migrations:check (config snapshot data-safe), docs suite (166), i18n parity, tsc, oxlint, oxfmt, knip
  • Container image build + container-sandbox-runtime-test.ts (needs Docker/CI)
  • Live managed turn through the Bifrost gateway /openai/v1/responses route (needs a deployed stack)

Closes #2422

Add agentKind 'codex' as a first-class external sandbox runtime alongside
Claude Code, Cursor, and Hermes:

- Codex adapter (services/platform/lib/agent-adapters/codex/): headless
  `codex exec --json` with every posture key on -c overrides (the only
  config surface fresh + resume share), prompt on stdin behind the '-'
  sentinel, systemPromptAppend via developer_instructions, managed gateway
  via a custom Responses-API model provider whose bearer key rides env_key
  (never argv), BYO against OpenAI's own API with OPENAI_API_KEY, MCP
  servers with env_vars-whitelisted secrets, native web_search disabled for
  managed runs unless nativeWebTools.
- JSONL parser mapped to AgentEvent (thread/turn/item events, usage on
  turn.completed, no zero-token usage rows), with a fixture captured from a
  real codex-cli 0.142.5 run.
- Schema/UI/runtime wiring: agentKind literals, readiness, agent editor
  kind picker, model selector types, capability-based turn lifecycle.
- Harden stored-kind coercions (steer delivery, turn recovery) with a
  PRODUCT_AGENT_SLUGS membership guard instead of per-slug ternaries.
- Sandbox image installs pinned @openai/codex; container test covers it.
- builtin-configs/agents/chat/codex.json composer agent; gpt-5.5 catalog
  entries carry nativeModelId for the BYO vendor-native dialect.
- Docs (en/de/fr) + tale-daemon cross-links + locale strings.

Closes #2422
@yannickmonney
yannickmonney enabled auto-merge (squash) July 7, 2026 06:04
@yannickmonney
yannickmonney merged commit 33b4416 into main Jul 7, 2026
15 of 19 checks passed
@yannickmonney
yannickmonney deleted the feat/codex-external-agent-2422 branch July 7, 2026 11:47
yannickmonney added a commit that referenced this pull request Jul 7, 2026
…leet

The budget was set at 4400 MB when the image was ~4.0 GB; the six external
agent CLIs added since (Cursor #2481, Hermes #2500, Gemini #2535, Codex
#2536, Pi #2550, OpenClaw #2555) grew it to ~4.9 GB and none of those PRs
updated the budget, so the Validate images gate is red on main too. Document
the fleet as a named cost and restore the ~10% headroom convention at 5400.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Implement Codex as a sandbox external agent (Claude Code parity)

1 participant