Execution model
OpenAI runs the agent loop, manages conversation context, and supplies delegation tools. CoreWeave runs the executor and the programs the agents write. Your application manages sandbox provisioning, file transfer, and cleanup. The coordinator and its subagents share one sandbox and one filesystem. Creating a subagent doesn’t create a separate CoreWeave sandbox. Give each specialist its own output files and let the coordinator own the final report. These file assignments are conventions for avoiding write conflicts, not access controls. See OpenAI’s multi-agent guide.Requirements
Before you run the example, meet these requirements:- W&B API 키와 CPU 샌드박스 1개를 실행할 수 있는 용량이 필요합니다. 자격 증명 선택을 참고하세요.
- Agents API 액세스 권한과 선택한 모델에 대한 액세스 권한이 있는 OpenAI 프로젝트가 필요합니다.
- Python과
uv가 필요합니다. 버전과 lockfile은 함께 제공되는 레시피에 지정된 것을 사용하세요. api.openai.com에 대한 아웃바운드 HTTPS 연결과codex-cloud-environments.chatgpt.com에 대한 보안 WebSocket 액세스가 필요합니다. 이미지를 설정할 때는 executor와 런타임 의존성을 설치하는 데 사용하는 패키지 레지스트리에도 액세스할 수 있어야 합니다.
Keep application and executor credentials separate
This example uses three credentials: one sandbox credential and two OpenAI keys. Each credential belongs to a single component, which keeps application access out of the sandbox:
레시피는 기본적으로 CoreWeave 인증을 사용합니다. W&B 키를 사용하려면
--sandbox-auth wandb를 전달하세요. 샌드박스 자격 증명은 선택한 것 하나만 있으면 되지만,
어느 모드를 사용하든 OpenAI 키는 두 개 모두 필요합니다. 애플리케이션이 선택한
모드를 기록해 두므로, 정리할 때도 동일한 공급자 자격 증명이 사용됩니다.
The OpenAI application key requires api.agents.read, api.agents.write, and
api.responses.write. Create the separate environment key in
Agents > Environments > Keys.
It must have the same organization, project, and user or service-account ownership
as the session. Set unrelated permissions to None.
The recipe passes the restricted executor key through the environment_variables
argument in the SDK. It doesn’t configure a secret store.
Upload only task inputs. Keep application credentials, local configuration, and
the verifier outside the sandbox. Follow the
OpenAI authentication instructions.
Connect an agent session
The runnable recipe implements these steps with the OpenAI and CoreWeave SDKs:- Create a self-hosted Agents API session and save its session ID and environment
ID. Use the exact returned
remote_urlwhen starting the executor. - Create a CoreWeave sandbox with an explicit maximum lifetime and both Python and Node.
- Start
codex exec-serverwith the returned environment ID and unchanged remote URL. Inject only the restricted executor key asCODEX_API_KEY. - Upload the synthetic inputs and task instructions, then confirm the environment connection. Submit the task and observe its outcome.
- Retrieve generated artifacts and API activity records before cleanup.
client.beta.agents.sessions.create():
--require-exit-codes check requires numeric zero-exit evidence for
every specialist. Overlapping started_at and completed_at intervals show
concurrent subagent turns. These timestamps have whole-second precision, so they
don’t prove simultaneous shell processes or a speedup over a sequential run.
Run the example
Follow the recipe setup and run steps. The recipe includes original synthetic data, a task specification, the application, and an independent verifier. Inspect the downloaded report alongside the verifier’s findings. You can also inspect session turns and tool calls in OpenAI Logs > Agents while the session exists. Select the matching organization and project. This example doesn’t provide a chat UI or establish ChatGPT or Codex app continuity. For an existing command-line interface (CLI) workflow, see OpenAI Agents API in cws-agent. The recipe uses the SDKs directly and doesn’t require that CLI.Session, sandbox, and file lifetimes
Manage the conversation, compute, and workspace files separately when choosing what to preserve.
Choose the compute lifetime explicitly. The recipe sets a 20-minute maximum
lifetime. A maximum lifetime is a cap, not an inactivity timer that each prompt
refreshes.
Reconnecting an executor to the same running sandbox retains its workspace. Starting
replacement compute with the same environment ID doesn’t restore its files.
Download artifacts or use CoreWeave persistence features before stopping compute.
The recipe downloads artifacts and deletes its resources. It doesn’t
implement automatic recovery or snapshot and restore.
Stopping a sandbox doesn’t delete its API conversation. Deleting the conversation
doesn’t stop the sandbox. Attempt both cleanup operations and report each failure.
Handle failures
To investigate failures, use the following guidance:- The executor never connects: check environment-key ownership, outbound network access, executor compatibility, and the exact remote URL returned by OpenAI.
- OpenAI reports a usage or billing limit: check the OpenAI organization and project billing limits before retrying. An executor connection alone doesn’t establish that a model turn can run.
- The stream disconnects or the client times out: inspect session state and saved events before retrying input. A timeout doesn’t itself cancel cloud work.
- Delegation or overlap isn’t observed: read the saved activity evidence. A correct report alone is insufficient evidence of a parallel multi-agent run.
- The OpenAI environment expires: inspect its state before retrying. The recipe may wait until its work deadline rather than fail immediately.
- The sandbox expires: recover saved artifacts if available. A replacement sandbox requires an explicit file-restoration policy.
- The application is interrupted: use the recipe’s saved resource journal and cleanup command. The maximum sandbox lifetime is a fallback, not a substitute for deleting the API session.