Python SDK 按 turn 换沙箱,不要一直 full_access

pip install openai-codex。thread_start 定默认沙箱,后一轮 run 可以改成只读审查。自研客户端仍用 app-server,不要用已删除的 mcp-server。

from openai_codex import Codex, Sandbox

with Codex() as codex:
    thread = codex.thread_start(
        model="gpt-5.6-terra",
        sandbox=Sandbox.workspace_write,
    )
    thread.run("Make the requested change.")
    review = thread.run("Review the diff only.", sandbox=Sandbox.read_only)
    print(review.final_response)

已有 asyncio 循环用 AsyncCodex。发布包自带钉死的 CLI 运行时;只有要对照本机二进制时才 CodexConfig(codex_bin=...)

Sandbox.read_only / workspace_write / full_access。省略时用 app-server 默认。传给 run / turn 的沙箱会作用到这一轮和之后。TypeScript 仍是 @openai/codex-sdk,服务端、Node 18+。CI 用 SDK;自研 IDE 走 app-server。

来源