Field SOP
Field SOP

Freeload OpenAI's Top Agent Foundation: The Codex Harness Integration SOP - a Three-Stage Rocket from One Command to a Production Runtime

The integration SOP for freeloading OpenAI's top agent foundation: a three-stage rocket. Stage 0 authentication (login_chatgpt / login_api_key; keys in env vars, never prompts) -> Stage 1 codex exec, one command for CI/scripts -> Stage 2 the Codex SDK as a callable function (startThread/run, outputSchema structured output, thread persistence in ~/.codex/sessions with resumeThread breakpoint resume, runStreamed event streams, sandbox and filesystem-granularity permission config examples) -> Stage 3 codex app-server as a production runtime (JSON-RPC 2.0, generate-json-schema, first-class Approvals semantics, -32001 overload retry, /readyz /healthz probes). Includes a 10-item pre-launch checklist and five classic pitfalls (keys in prompts, trusting sandbox defaults, non-Git directories, re-running instead of resuming, jumping to app-server on day one). All examples from the official repo docs; not legal or security-compliance advice.

Published August 22, 20267 min read
<!-- codex-harness-integration-sop | sop | Freeload OpenAI's Top Agent Foundation: The Codex Harness Integration SOP - a Three-Stage Rocket from One Command to a Production Runtime -->

Last week (2026-08-19) OpenAI announced "Codex as a platform," making the Codex Harness an officially embeddable agent foundation for third-party products (background in OpenAI Hands Over the Agent's Engine). Three entry points are on the table: codex exec, the Codex SDK, and codex app-server.

This SOP answers one concrete question: how an ordinary team puts this foundation to work at a "three-stage rocket" cadence - from one working command, to calling it from code, to a production-grade runtime. Every stage ships a minimal runnable example and an upgrade criterion, all based on the openai/codex repository's official docs (GitHub API snapshot 2026-08-22).

Two boundaries up front. First: the Harness being open source (Apache-2.0) does not make the models free - tokens still bill normally. Second: this is an integration path write-up, not legal or security-compliance advice; run it through your own security review before production.

Stage 0: Authentication and Environment

All three stages share one auth layer. The official recommended path from the Python SDK:

python
from openai_codex import Codex

with Codex() as codex:
    login = codex.login_chatgpt()      # ChatGPT browser login
    print(login.auth_url, login.wait().success)
    # or API key: codex.login_api_key("sk-...")

Key points: an existing Codex login is reused automatically; the Python SDK (pip install openai-codex, Python 3.10+) bundles the matching CLI automatically; the TS SDK (npm install @openai/codex-sdk, Node 18+) instead spawns the CLI and exchanges JSONL events over stdin/stdout. Keys go through environment variables or the login flow - never into the prompt.

Stage 1: codex exec - a One-Command Integration

For: CI pipelines, cron jobs, one-off background tasks. Zero code refactoring.

bash
codex exec --json "Analyze this repo and produce a risk list"

Upgrade criterion: move to Stage 2 when you need to pass state between tasks (feed one task's conclusions into the next) or need structured output for downstream programs.

Stage 2: The Codex SDK - Calling the Agent Like a Function

For: orchestrating the agent from your own TS / Python services. Two core capabilities:

Multi-turn threads + breakpoint resume (threads persist in ~/.codex/sessions; a restarted process picks up where it left off):

typescript
import { Codex } from "@openai/codex-sdk";

const codex = new Codex();
const thread = codex.startThread({ workingDirectory: "/path/to/project" });
const turn = await thread.run("Diagnose the test failure and propose a fix");
console.log(turn.finalResponse);
// after a restart: codex.resumeThread(savedThreadId) carries on

JSON Schema structured output (the agent's answer is forced to conform to your schema - downstream systems never parse prose again):

typescript
const schema = {
  type: "object",
  properties: {
    summary: { type: "string" },
    status: { type: "string", enum: ["ok", "action_required"] },
  },
  required: ["summary", "status"],
} as const;

const turn = await thread.run("Summarize repository status", { outputSchema: schema });

When you need real-time progress (tool calls, file changes), use runStreamed() for the event stream instead of the buffered run().

The official switches for safety and sandboxing (these parameters are your first set of reins):

typescript
const codex = new Codex({
  config: {
    sandbox_workspace_write: { network_access: false },  // no network egress inside the sandbox
    default_permissions: "audit",
  },
  configOverrides: [
    // filesystem granularity: root read-only, .env explicitly denied
    'permissions.audit.filesystem={":root"="read","/path/to/project/.env"="deny"}',
  ],
});

Upgrade criterion: move to Stage 3 when you need a custom UI, your own approval flow, or event streams forwarded raw to the frontend.

Stage 3: codex app-server - a Production-Grade Agent Runtime

For: the agent itself is part of your product. codex app-server is the same interface that powers the Codex VS Code extension: a JSON-RPC 2.0 protocol service supporting stdio (default, JSONL), WebSocket (experimental), and Unix socket transports.

Grab the schema first (generated per version so interfaces stay aligned):

bash
codex app-server generate-ts           # TypeScript types
codex app-server generate-json-schema  # JSON Schema bundle

Three engineering points (all from the official README):

  1. Approvals are a first-class protocol citizen. The App Server API includes Approvals semantics - high-risk actions suspend and wait for your confirmation. Build this into your product as a human-in-the-loop screen; do not take the shortcut of auto-approving everything.
  2. Treat overload as retryable. Under saturation the server returns JSON-RPC error -32001 ("Server overloaded; retry later"), and the official guidance is exponential backoff with jitter on the client.
  3. Health probes come for free. In --listen ws:// mode, GET /readyz (listener ready) and GET /healthz (200 when no Origin header) plug straight into your liveness checks.

The 10-Item Pre-Launch Checklist

  1. Credentials via environment variables / KMS - not in code, not in prompts
  2. Sandbox mode declared explicitly (workspace-write, network egress off unless required)
  3. Filesystem-granularity permissions: .env and secret directories explicitly denied
  4. High-risk actions (deletes, external sends, payments) gated by approval - no default allow
  5. Full behavioral logs: thread id, per-turn usage, tool-call sequence
  6. Dual caps on tokens and action counts + automatic circuit-breaking on anomalies
  7. Long tasks resume via resumeThread() - never blindly re-run (you pay twice)
  8. Structured output via outputSchema - never regex-parse prose
  9. Retry logic wired for the -32001 app-server overload error
  10. Canary first: read-only tasks for two weeks before enabling writes

Five Classic Pitfalls

  • Pasting the key into the prompt to "save time" - logging systems store prompts wholesale, which means the key lands in your logs.
  • Trusting default sandbox settings - defaults lean permissive; tighten network egress and file scope yourself (for the cautionary tale, see OpenAI Hits the Brakes: OpenAI's own eval sandbox was breached from the inside by its own agent).
  • Starting in a non-Git directory - Codex requires the working directory to be a Git repo (so actions stay reversible); to skip it use skipGitRepoCheck: true, but know which insurance you're dropping.
  • Re-running the whole task after a failure - thread persistence exists precisely for resuming; a full re-run burns double the tokens.
  • Jumping to app-server on day one - the protocol layer couples deeply and is expensive to migrate; if two stages of SDK solve it, don't take the third. For the five-way vendor comparison, see the Agent Runtime Comparison.

One-line closer: the two-to-three months you save by freeloading the foundation is exactly enough to build approvals, audit, and circuit-breaking properly - where you spend the saved time decides whether this foundation is a productivity engine or an incident factory.

FAQ

Q1: Do I need to install all three of exec / SDK / app-server? A1: No - pick one by integration depth: scripts and CI use codex exec; in-code orchestration uses the SDK; only custom UI and approval flows need app-server. Coupling depth doubles at each level; always start at the lowest level that suffices.

Q2: What's the SDK's relationship to the CLI - will versions conflict? A2: The SDK isn't a rewrite; it wraps the CLI. The TS SDK spawns the @openai/codex CLI and exchanges JSONL events; the Python SDK (openai-codex) bundles the matching CLI (openai-codex-cli-bin) automatically, with SDK versions tracking CLI releases - you never manage version matching by hand.

Q3: The process died mid-task - is the progress gone? A3: No. Threads persist in ~/.codex/sessions; resumeThread(threadId) picks up where it left off without re-running (and without re-burning tokens). Passing the thread id across processes via something like process.env.CODEX_THREAD_ID is the common pattern in TS.

Q4: With Apache-2.0 open source, what do I still pay for in commercial use? A4: The framework layer is free - modify and commercialize it. Model inference bills through OpenAI (API key or ChatGPT account quota). Also note the IDE Extension and Codex Cloud are outside the open-source scope.

Q5: My product already has a homegrown agent loop - is migrating worth it? A5: The test is "where's your differentiation." If your team's energy goes into maintaining the loop, context management, and tool scheduling - things official runtimes now give away - migration is net positive. If your differentiation is the execution layer itself (or you need deep customization), keep your build but benchmark against Codex's designs (thread resume, approval semantics, structured output) to close gaps. The reins layer (approvals / audit / circuit-breaking) you build yourself either way - see the Agent Guardrails Deployment SOP.


References

  • openai/codex repository (GitHub API snapshot 2026-08-22, Apache-2.0, 111,646 stars)
  • sdk/typescript/README.md: startThread / run / runStreamed / outputSchema / resumeThread / workingDirectory / env / config overrides
  • sdk/python/docs/getting-started.md: installation, the three login flows, the thread_start(sandbox=...) example
  • codex-rs/app-server/README.md: JSON-RPC 2.0 protocol, stdio/ws/unix transports, Approvals, the -32001 overload retry, /readyz /healthz, generate-ts / generate-json-schema
  • OpenAI official blog (2026-08-19): Codex as a platform

This article is based on official documentation (as of 2026-08-22) and is not legal or security-compliance advice; run production launches through your own security review.

This article is AI-assisted and human-edited. Last updated: 2026-08-22

FAQ

Do I need to install all three of exec / SDK / app-server?
A1: No - pick one by integration depth: scripts and CI use `codex exec`; in-code orchestration uses the SDK; only custom UI and approval flows need app-server. Coupling depth doubles at each level; always start at the lowest level that suffices.
What's the SDK's relationship to the CLI - will versions conflict?
A2: The SDK isn't a rewrite; it wraps the CLI. The TS SDK spawns the `@openai/codex` CLI and exchanges JSONL events; the Python SDK (`openai-codex`) bundles the matching CLI (`openai-codex-cli-bin`) automatically, with SDK versions tracking CLI releases - you never manage version matching by hand.
The process died mid-task - is the progress gone?
A3: No. Threads persist in `~/.codex/sessions`; `resumeThread(threadId)` picks up where it left off without re-running (and without re-burning tokens). Passing the thread id across processes via something like `process.env.CODEX_THREAD_ID` is the common pattern in TS.
With Apache-2.0 open source, what do I still pay for in commercial use?
A4: The framework layer is free - modify and commercialize it. Model inference bills through OpenAI (API key or ChatGPT account quota). Also note the IDE Extension and Codex Cloud are outside the open-source scope.
My product already has a homegrown agent loop - is migrating worth it?
A5: The test is "where's your differentiation." If your team's energy goes into maintaining the loop, context management, and tool scheduling - things official runtimes now give away - migration is net positive. If your differentiation is the execution layer itself (or you need deep customization), keep your build but benchmark against Codex's designs (thread resume, approval semantics, structured output) to close gaps. The reins layer (approvals / audit / circuit-breaking) you build yourself either way - see the [Agent Guardrails Deployment SOP](/en/ai-agent-guardrails-deployment-sop). --- **References** - openai/codex repository (GitHub API snapshot 2026-08-22, Apache-2.0, 111,646 stars) - `sdk/typescript/README.md`: startThread / run / runStreamed / outputSchema / resumeThread / workingDirectory / env / config overrides - `sdk/python/docs/getting-started.md`: installation, the three login flows, the thread_start(sandbox=...) example - `codex-rs/app-server/README.md`: JSON-RPC 2.0 protocol, stdio/ws/unix transports, Approvals, the `-32001` overload retry, /readyz /healthz, generate-ts / generate-json-schema - OpenAI official blog (2026-08-19): Codex as a platform This article is based on official documentation (as of 2026-08-22) and is not legal or security-compliance advice; run production launches through your own security review.

Related

Field SOP

428B Weights Are Out, Budget 8 H100s: M3.1 Flash Local Deploy

A deployment log for M3.1 Flash (428B, 23B active). Cold water first: there is no consumer or single-GPU recipe anywhere official - the smallest validated tiers are 4x Blackwell (B200/B300/GB200/GB300, TP4), 4x AMD MI355X (TP4), or a full node of 8x H100/H200 (TP8, FP8 path). Weights come from HF or ModelScope (public, not gated); three size calibers coexist: community-count 252.4GB over 48 shards plus a 2.3GB DSpark head, and the vLLM recipe listing NVFP4 at 285GB, MXFP4 at 293GB, FP8 at 533GB; there is no official quantized repo. vLLM needs 0.33.0 or newer (absent from PyPI on release day, so use the vllm/vllm-openai:minimax-m31-flash Docker image or nightly); three official commands transcribed verbatim - H100/H200 TP8, GB200 TP4, MI355X TP4 - all forcing --block-size 128 and --disable-hybrid-kv-cache-manager (omit it and you get No common block size for 16); 1M context opens via --max-model-len (the Hopper sample caps at 262144). SGLang is not merged to main yet (Blackwell needs the MSA kernel at a pinned commit plus nvcc 13.4 minimum - cu130 does not count). The memory ledger: BF16 at roughly 856GB is an inference, not an official figure; 23B active lowers compute, not the VRAM floor - all 428B experts must stay resident, which is exactly why consumer cards are out; total KV cache for 1M context is unpublished. Domestic compute rides FlagOS Day-0 across nine chips (Huawei Ascend included, via SGLang-plugin-FL), numbers flagged as FlagOS official. Thirteen official error notes collected with fixes: HugeTLB 560GiB, B200 OOM, parser spelling, and more. License: MiniMax Community License, commercial attribution plus the 20-million-dollar threshold. One line of reality: 428B weights are out - budget 8 H100s.

Oct 24, 20269 min read
Field SOP

Nemotron 3.5 Bolt Local Deployment: 74B on a 24GB Card

NVIDIA released Nemotron 3.5 Bolt 74B-A9B 24GB on October 15, 2026: a compression of the 120B Super VL via Star Elastic budget-conditioned architecture search (expert top-K down from 22 to 9, distilled recovery training over 120B tokens), on a hybrid Mamba-2 and Transformer architecture. The quantization plan is the story - the expert layers that dominate the weights drop to IQ2_XXS at 2.0625 bits per element (about 19GB), Mamba linear layers use NVFP4, and lm_head, embeddings, and attention stay at Q8_0, landing the full model at 22-24GB with accuracy recovered through quantization-aware distillation from the compression stage onward. Four deployment routes, with commands: Ollama (supported since 0.40.5, ollama run nemotron-3.5-bolt, a 25GB download, verify 100 percent GPU via ollama ps); Unsloth (UD-IQ2_XXS about 22GB, UD-IQ1_M about 20.3GB, ctx from a conservative 4096); llama.cpp official recipes (builds after October 15 to recognize nemotron_h_moe; the 28GB recipe runs 65K context with 8-bit KV and 6 draft tokens, the 32GB recipe reaches 262K; llama-server defaults to port 9931 since b11521); and vLLM (Blackwell SM120 with the LiLiCorr drafter for multi-user serving). Two context starting points coexist: 16K-32K for bare weights, 4K for Unsloth whose default drafter eats another 1-2GB. Eight troubleshooting entries cover OOM context cuts, layers spilling to system RAM, the missing --mmproj flag, and the shared 16384 max_tokens budget. OpenMDW-1.1 grants free unrestricted commercial use, leaves outputs unencumbered, requires notices only on redistribution, and carries a patent-retaliation clause. Vendor-reported: GPQA Diamond 86.4, Terminal-Bench 2.1 at 51.0, PinchBench first in class (83.99 TPS on RTX Spark; no official consumer-card figure). The 4GB Bolt E4B followed on October 23.

Oct 23, 20268 min read
Field SOP

Xing4.0-29B-Intent Local Deploy: 4B Active, Which Command?

Getting Xing4.0-29B-Intent running hinges on a detail that trips most people up: the official deployment instructions do not live in the intent repository but in the base model repository. The intent README only says to replace the model path with the Xing4.0-29B-Intent weights and set --served-model-name to Xing4.0-29B-Intent, so the full vLLM and SGLang launch commands must be taken from the Xing4.0-29B-A4B base repo. Several flags are hard requirements: --trust-remote-code is mandatory because model_type is the in-house xing4_0 architecture, neither llama nor qwen; --tensor-parallel-size 2 implies at least two cards; --max-model-len 262144 matches the 256K context; --reasoning-parser xing4_0 and --tool-call-parser xing4_0 supply the matching parsers; --speculative-config uses the mtp method; and --gpu-memory-utilization 0.90 with --max-num-seqs 4 is the official example ratio. The weights ship as 41 safetensors shards totaling 62.43 GB, and the only official quantizations are FP8 (33.17 GB, e4m3) and GGUF (a single IQ4_NL file at 17.75 GB) - there is no AWQ, GPTQ, or INT8 safetensors. Minimum VRAM is not published at all; the official line is to configure GPU memory, parallelism, and context length for your environment. What the base repo does spell out: bfloat16 is required because the mHC path errors out on FP16 or quantized weights, --pipeline-parallel-size greater than 1 is not yet supported, the CUDA mHC path needs tilelang installed, and the host needs Docker 24.0 or newer with driver 535 or newer. The Ascend route explicitly wants 910B2 NPUs with at least two cards, with three official quay.io images (none of which bundle the weights). Consumer and CPU paths appear only in the base llama.cpp docs: int4 weights quantized with IQ4_NL come to about 19 GB and fit on a single consumer GPU, with an RTX 3090 24 GB as the example. The SDK is just an httpx HTTP client and is not on PyPI, and structured output comes in two layers - the model's native category plus args array, and SDK-guided JSON Schema constraints through vLLM response_format. The license is Apache-2.0, yet the weight side has no standalone LICENSE file, the repository LICENSE is an unfilled placeholder template, and the original terms of the 61 upstream datasets still need checking.

Oct 22, 20269 min read