For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
기본 탐색

Codex SDK

로컬 Codex 에이전트를 프로그래밍 방식으로 제어

Codex CLI, IDE 확장 또는 Codex 클라우드로 Codex를 사용한다면 프로그래밍 방식으로도 제어할 수 있습니다.

다음과 같은 작업에는 SDK를 사용하세요:

  • CI/CD 파이프라인의 일부로 Codex 제어하기
  • Codex와 상호작용해 복잡한 엔지니어링 작업을 수행하는 자체 에이전트 만들기
  • 내부 도구와 워크플로우에 Codex 통합하기
  • 자체 애플리케이션에 Codex 통합하기

Codex SDK를 사용해 CI 작업을 비롯한 코딩 작업을 자동화하세요. 인증, 대화 기록, 승인, 스트리밍되는 에이전트 이벤트를 처리하는 맞춤형 클라이언트를 만들려면 Codex App Server를 사용하세요.

codex mcp-server 명령어와 독립 실행형 codex-mcp-server 바이너리는 제거되었습니다. 기존 통합에는 Codex App Server를 사용하세요.

베타 액세스 권한이 있고, 레포지토리나 변경 사항을 스캔해 구조화된 보안 이슈와 검사 범위 정보를 받아야 한다면 Codex Security TypeScript SDK를 사용하세요.

TypeScript 라이브러리

TypeScript 라이브러리를 사용하면 애플리케이션에서 로컬 Codex 스레드를 시작하고, 이어서 진행하고, 재개할 수 있습니다.

이 라이브러리는 서버 측에서 사용하세요. Node.js 18 이상이 필요합니다.

설치

먼저 npm으로 Codex SDK를 설치하세요:

npm install @openai/codex-sdk

사용법

Codex에서 스레드를 시작하고 프롬프트로 실행하세요.

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

const codex = new Codex();
const thread = codex.startThread();
const result = await thread.run(
  "Make a plan to diagnose and fix the CI failures"
);

console.log(result.finalResponse);

run()을 다시 호출해 같은 스레드에서 계속 진행하거나, 스레드 ID를 지정해 이전 스레드를 재개하세요.

// running the same thread
const result = await thread.run("Implement the plan");

console.log(result.finalResponse);

// resuming past thread

const threadId = "<thread-id>";
const thread2 = codex.resumeThread(threadId);
const result2 = await thread2.run("Pick up where you left off");

console.log(result2.finalResponse);

자세한 내용은 TypeScript 레포지토리를 참고하세요.

Python 라이브러리

Python SDK는 JSON-RPC로 로컬 Codex app-server를 제어합니다. Python 3.10 이상이 필요합니다. 배포된 SDK 빌드에는 버전이 고정된 Codex CLI 런타임 종속성이 포함되어 있습니다.

설치

SDK를 설치하려면 다음 명령어를 실행하세요:

pip install openai-codex

배포된 SDK 빌드는 버전이 고정된 런타임을 자동으로 사용합니다. 특정 로컬 Codex 실행 파일을 의도적으로 사용하려는 경우에만 CodexConfig(codex_bin=...)을 전달하세요.

Python SDK는 안정 버전으로 제공됩니다. pip install openai-codex을 실행하면 최신 안정 버전이 설치됩니다. 더 새로운 사전 릴리스 빌드를 사용하려면 pip install --pre openai-codex를 실행하세요.

사용법

Codex를 시작하고 스레드를 만든 다음 프롬프트를 실행하세요:

from openai_codex import Codex, Sandbox

with Codex() as codex:
    thread = codex.thread_start(
        model="gpt-5.6-terra",
        sandbox=Sandbox.workspace_write,
    )
    result = thread.run("Make a plan to diagnose and fix the CI failures")
    print(result.final_response)

애플리케이션이 이미 비동기 방식으로 동작한다면 AsyncCodex를 사용하세요:

import asyncio

from openai_codex import AsyncCodex


async def main() -> None:
    async with AsyncCodex() as codex:
        thread = await codex.thread_start(model="gpt-5.6-terra")
        result = await thread.run("Implement the plan")
        print(result.final_response)


asyncio.run(main())

샌드박스 프리셋

스레드를 생성할 때나 이후 턴의 파일 시스템 접근 권한을 변경할 때 동일한 Sandbox 프리셋을 사용하세요:

from openai_codex import Codex, Sandbox

with Codex() as codex:
    thread = codex.thread_start(sandbox=Sandbox.workspace_write)
    thread.run("Make the requested change.")
    review = thread.run("Review the diff only.", sandbox=Sandbox.read_only)

사용 가능한 프리셋:

  • Sandbox.read_only: 파일 읽기를 허용하고 쓰기는 허용하지 않습니다.
  • Sandbox.workspace_write: 파일 읽기를 허용하고, 워크스페이스와 쓰기 가능하도록 설정된 루트 경로 내에서 쓰기를 허용합니다.
  • Sandbox.full_access: 파일 시스템 접근 제한 없이 실행합니다.

sandbox=를 생략하면 app-server에 설정된 기본값이 사용됩니다. run(...) 또는 turn(...)에 전달한 샌드박스 설정은 해당 턴과 같은 스레드의 이후 턴에 적용됩니다.

자세한 내용은 Python 레포지토리를 참고하세요.