Using Codex

Cloud 环境

管理 Cloud 任务的环境、依赖和初始化要求。

使用 environments 控制 Codex 在 cloud tasks 期间安装什么、运行什么。例如,你可以添加 dependencies,安装 linters、formatters 等 tools,并设置 environment variables。

Codex settings 中配置 environments。

Codex cloud tasks 如何运行

提交 task 后会发生以下流程:

Codex 创建 container,并在所选 branch 或 commit SHA 上 checkout 你的 repo。

Codex 运行你的 setup script;当 cached container 被恢复时,还会运行可选的 maintenance script。

Codex 会应用你的 internet access settings。Setup scripts 会带 internet access 运行。Agent internet access 默认关闭,但如有需要,你可以启用 limited 或 unrestricted access。参见 agent internet access

Agent 会循环运行 terminal commands。它会编辑 code、运行 checks,并尝试验证自己的工作。如果你的 repo 包含 AGENTS.md,agent 会用它查找项目专属的 lint 和 test commands。

Agent 完成后,会显示回答和它修改过的文件 diff。你可以打开 PR,或继续提 follow-up questions。

默认 universal image

Codex agent 运行在名为 universal 的默认 container image 中,它预装了常见 languages、packages 和 tools。

In environment settings, 选择 设置 package versions 到 pin versions of Python, Node.js, 和 other runtimes.

For details on what’s installed, see openai/codex-universal for a reference Dockerfile 和 an image that can be pulled 和 tested locally.

While codex-universal comes 使用 languages pre-installed for speed 和 convenience, you can also 安装 additional packages 到 the container using setup scripts .

Environment variables 和 secrets

Environment variables 会在 task 全程生效(包括 setup scripts 和 agent phase)。

Secrets 类似 environment variables,但有以下区别:

它们会使用额外一层 encryption 存储,并且只在 task execution 时解密。

它们只对 setup scripts 可用。出于安全原因,agent phase 开始前会移除 secrets。

Automatic setup

对于使用常见 package managers(npm、yarn、pnpm、pip、pipenv 和 poetry)的项目,Codex 可以自动安装 dependencies 和 tools。

Manual setup

如果你的 development setup 更复杂,也可以提供 custom setup script。例如:

# Install type checker pip install pyright # Install dependencies poetry install --with test pnpm install

Setup scripts 会在与 agent 分离的 Bash session 中运行,因此 export 之类的 commands 不会延续到 agent phase。要持久化 environment variables,请把它们添加到 ~/.bashrc,或在 environment settings 中配置。

Container caching

Codex 最多缓存 container state 12 小时,以加速新的 tasks 和 follow-ups。

当 environment 被缓存时:

Codex clone repository 并 checkout default branch。

Codex 运行 setup script,并缓存生成的 container state。

当 cached container 被恢复时:

Codex checkout task 指定的 branch。

Codex 运行 maintenance script(可选)。当 setup script 是在较旧 commit 上运行、dependencies 需要更新时,这很有用。

Codex 自动 invalidates the cache 如果 you change the setup script, maintenance script, environment variables, 或 secrets。如果 your repo changes in a way that makes the cached state incompatible, 选择 Reset cache on the environment page.

对于 Business 和 Enterprise users,cache 会在所有有权访问该 environment 的 users 之间共享。让 cache 失效会影响 workspace 中该 environment 的所有 users。

Internet access 和 network proxy

Setup script phase 可以使用 internet access 来安装 dependencies。Agent phase 的 internet access 默认关闭,但你可以配置 limited 或 unrestricted access。参见 agent internet access

出于 security 和 abuse prevention 目的,environments 会在 HTTP/HTTPS network proxy 后运行。所有 outbound internet traffic 都会经过该 proxy。

站内延伸阅读