HeadlinesBriefing favicon HeadlinesBriefing.com

Running Codex as a Headless Agent

Towards Data Science •
×

Codex is usually used interactively in a terminal or IDE, but it can also become a callable part of our own workflow. In headless mode, Codex stops being a conversation partner and becomes just one callable step in a larger process: the workflow supplies the task context, and Codex returns an output the next step can easily consume. This pattern fits repeatable processes where one step needs agentic work, like a scheduled weekly research digest or an automated CI review.

The case study builds a three-step Python workflow: prepare_research_task() assembles the prompt, output schema, and file paths; run_codex() invokes Codex; render_digest() converts the structured brief into an HTML page. Instead of asking for a free-form report, the prompt requires structured JSON so the next step can consume the result programmatically.

To run Codex non-interactively, install the CLI via npm, then use codex exec with --search for live web search, --model gpt-5.5-codex, --output-schema to define the expected shape, -o for the final answer, and --json to emit a JSONL event trace. Sandbox options like read-only or workspace-write control local file access.

In the demo, researching AI data-center infrastructure over a 30-day window with up to 6 events, Codex produced a structured brief that rendered into outputs/digest.html with a summary, timeline, event cards, and source links.