Cordium documentation · Latest
Codex
This example drives OpenAI Codex from your own program via the Cordium SDKs to implement features in a TypeScript web application. For each task, the program starts an ephemeral Workspace from a pre-built Template in which the repository is already cloned and its dependencies are already installed, runs codex exec inside it, runs the test suite, collects the resulting diff and Codex's summary, and deletes the Workspace. This orchestration pattern is the building block of internal coding-agent platforms, evaluation harnesses and "best-of-N" setups (read a parallel version here).
As in all the AI examples, the OpenAI API key never enters the Workspace. Codex is configured with a custom model provider that points to an Octelium LLM Service, which injects the key on a per-request basis (read more here).
The Octelium Service
A Cluster administrator stores the OpenAI API key as an Octelium Secret and exposes the OpenAI API as an LLM Service:
The Users who run the program must be allowed to access the openai Service by a Policy.
The Template
The codex Template of the storefront Space clones the repository with a read-only token, installs Codex, configures its model provider and installs the npm dependencies. Since these are ON_CREATE tasks, they run once in the Template's pre-build and every Workspace starts with everything ready:
Create and pre-build the Template:
The read-only token is used by the Workspace's git credential helper, which means that it is readable inside the Workspace. Use a fine-grained token restricted to the Contents: read permission of the repository. To keep even that token out of the Workspace, clone the repository through an Octelium HTTP Service in a POST_START task instead, as shown in the Claude Code example.
The Orchestrator
The following Python program uses the Cordium SDK to run one Codex task and return its result. It runs with your own identity, or with a WORKLOAD User's identity in automation (read more about authenticating the SDKs here):
Here are a few notes about this program:
workspaces.run()creates and starts the Workspace, and waits until it isRUNNING. Since the Template is pre-built, this typically takes a few seconds.codex execruns non-interactively, streams its progress to stderr and writes its final message to/tmp/summary.md.--sandbox danger-full-accessdisables Codex's own sandbox, which is meant for developer machines; the Workspace is the sandbox here. Its standard input is redirected from/dev/nullsinceexecsessions do not signal the end of the standard input.execreturns the exit code instead of raising, unlesscheck=Trueis passed. Everyexecsession counts as activity, so the Workspace is not stopped by the inactivity timeout while Codex is working.The Workspace is always deleted, even if any step fails. To debug a failed run, skip the deletion and open a terminal in it from the web portal.
The equivalent flow is also available via the CLI, for example from a shell script: