SDK – Codex | OpenAI Developers
Service

SDK – Codex | OpenAI Developers

2026.06.02
·Service·by Homin.Lee
#Codex#OpenAI#Python#SDK#TypeScript

Key Points

  • 1The Codex SDK enables programmatic control of Codex, facilitating its integration into CI/CD pipelines, custom agents, and internal tools for complex engineering tasks.
  • 2Available as TypeScript (Node.js) and Python libraries, the SDK allows users to initiate, run, and resume conversational threads with Codex using prompts.
  • 3Advanced features include `Sandbox` presets (e.g., `read_only`, `workspace_write`, `full_access`) to manage and restrict Codex's file system access during operations.

This paper details the programmatic control of OpenAI's Codex engineering assistant through its dedicated Software Development Kits (SDKs), specifically for TypeScript and Python environments. The SDKs enable developers to integrate Codex functionalities into their applications, CI/CD pipelines, custom agents, and internal tools, providing a more comprehensive and flexible interface than its command-line or IDE extensions.

The TypeScript library is designed for server-side integration, requiring Node.js 18 or later. Installation is performed via npm install @openai/codex-sdk. Its core methodology revolves around thread management:

  • An instance of Codex is initialized (constcodex=newCodex();const codex = new Codex();).
  • A new conversational thread is initiated using codex.startThread(), returning a thread object.
  • Interactions with Codex occur by calling await thread.run("prompt string"), which sends a prompt and returns the result. Subsequent calls to thread.run() on the same thread object continue the conversation contextually.
  • Existing threads can be resumed using codex.resumeThread(threadId), allowing for persistent multi-turn interactions.

The Python library operates by controlling a local Codex app-server via JSON-RPC, requiring Python 3.10 or later. It is installed via pip install openai-codex and includes a pinned Codex CLI runtime dependency. Developers can optionally specify a custom Codex binary path. The library offers both synchronous and asynchronous interfaces:

  • Synchronous Usage: An instance of Codex is managed as a context manager (with Codex() as codex:). A new thread is started using codex.threadstart(model="gpt−5.4",sandbox=Sandbox.workspacewrite)codex.thread_start(model="gpt-5.4", sandbox=Sandbox.workspace_write), allowing for explicit model selection and initial sandbox configuration. Prompts are executed via thread.run("prompt string"), with results accessible through result.final_response.
  • Asynchronous Usage: The AsyncCodex class provides an asynchronous interface, suitable for asynchronous applications (async with AsyncCodex() as codex:). Thread initiation (await codex.thread_start(...)) and prompt execution (await thread.run(...)) are performed using await calls.

A key methodological aspect across both SDKs is the management of Sandbox presets, which govern Codex's filesystem access permissions during execution. These presets can be applied when starting a thread or modified for specific turns using the sandbox parameter in thread.run() or thread.turn(). The available presets include:

  • Sandbox.read_only: Allows Codex to read files but prevents any write operations.
  • Sandbox.workspace_write: Grants read and write access within the designated workspace and configured writable roots.
  • Sandbox.full_access: Removes all filesystem access restrictions, providing unrestricted read/write capabilities.
If the sandbox parameter is omitted, the app-server's configured default sandbox setting is used. Importantly, a sandbox specified for a particular run() or turn() call applies to that specific interaction and all subsequent turns within the same thread, ensuring consistent permission enforcement.