Agentic AI AcademyAgentic AI Academy

Delegating to Codex Cloud

Background, parallel tasks in isolated sandboxes

Intermediate 13 minBuilderDecision-maker
What you'll be able to do
  • Explain the Codex cloud execution model: one isolated container per task, running in the background and in parallel
  • Name the five entry points for delegating a cloud task and what each is good for
  • Delegate a task from the CLI with `codex cloud` and `codex cloud exec`, including the required `--env` and best-of-N `--attempts`
  • Inspect cloud tasks with `codex cloud list` and pull a finished diff back into your working tree with `codex apply`
  • Apply a clear rule of thumb for choosing local versus cloud, and review the pull request Codex opens in the connected repo
  • Account for the shared 5-hour usage window and the plans that include cloud access
At a glance

Codex cloud runs coding tasks in isolated sandbox containers, in the background and in parallel, so you can fire off heavy work and keep coding. This lesson teaches when to delegate to the cloud versus stay local, the entry points (web, mobile, IDE, GitHub, CLI), how to delegate from the terminal with `codex cloud` and best-of-N attempts, and how to bring the resulting diffs back with `codex apply` — then review the PR Codex opens for you.

  1. 1The mental model: hand the job to a remote teammate
  2. 2Why isolated containers matter
  3. 3Five ways to delegate a task
  4. 4Delegating from the CLI: `codex cloud`
  5. 5Inspecting tasks and bringing diffs home
  6. 6From task to pull request
  7. 7Local or cloud? A rule of thumb

The mental model: hand the job to a remote teammate

When you run codex in your terminal, the agent works on your machine — your files, your CPU, your shell. That's perfect for a tight back-and-forth, but it ties up your laptop and your attention for the whole run.

Codex cloud is the same agent, relocated. Instead of acting on your local checkout, it spins up a fresh cloud sandbox container, clones your repo into it at a branch or commit, and does the work there — while you carry on with something else. Think of it less like running a command and more like delegating a ticket to a remote teammate: you write a clear brief, hand it off, and check back on the result.

Two properties make this more than "the same thing, but slower to reach":

  • It runs in the background. Once you submit, you're free. The task keeps going whether or not your terminal, IDE, or laptop stays open.
  • It runs in parallel. Each task gets its own container, so you can have several cloud tasks churning at once — three independent bug fixes, or four attempts at the same hard problem — without them stepping on each other.

Every surface (web, mobile, IDE, GitHub, CLI) shares one ChatGPT account, so a task you start from the CLI is the same task you can monitor on the web or steer from your phone. The entry point is chatgpt.com/codex, and cloud needs a connected GitHub account so it can read the repo and open pull requests.

Key insight

Local is a conversation; cloud is a delegation

Local Codex is interactive — you watch and steer turn by turn. Cloud Codex is fire-and-forget — you write a complete brief, submit, and review the finished diff later. The skill shift is from pairing to delegating well.

Why isolated containers matter

The word isolated is doing real work in "isolated sandbox container." Each cloud task runs in a container that is separate from your machine and separate from every other task, and that buys you three things at once:

PropertyWhat it gives you
Isolation from your laptopA long migration or a risky refactor can't touch your local working tree, your dotfiles, or your running processes. The blast radius is the container.
Isolation between tasksParallel tasks don't share state, so one task's half-finished edits can't corrupt another's. Clean concurrency for free.
A reproducible starting pointThe container boots from a known base image (universal) with your dependencies installed by a setup script, so runs don't depend on "it works on my machine."

Isolation is also a security boundary. During the agent phase, the container's internet access is off by default — a deliberate guardrail against prompt injection and credential exfiltration from untrusted content the agent might read. (Setup scripts keep internet on so dependencies can install; the agent phase is the locked-down part.) You configure environments — base image, setup scripts, secrets, and that internet policy — per environment, and the next lesson covers them in depth. For now, the takeaway is simply: delegated work runs in a clean, contained, network-restricted box, not on your laptop.

Watch out

Agent-phase internet is OFF by default

Cloud sandboxes block outbound network during the agent phase unless you opt in. If a delegated task needs to hit an external API at run time (not just install deps at setup), it will fail until you widen the environment's internet policy. Verify the per-environment setting at developers.openai.com/codex/cloud/internet-access.

Five ways to delegate a task

There's no single "cloud button" — Codex meets you wherever you already are. All five routes start the same kind of background task in the same kind of container; they differ only in where you are standing when you hand it off.

Entry pointHow you trigger itBest for
ChatGPT webGo to chatgpt.com/codex, pick repo + branch, type a prompt, submitStarting from scratch, monitoring logs, managing several tasks
ChatGPT mobile (preview)Start / review / steer / approve from the appKicking off or unblocking work away from your desk
IDE extensionClick "Run in the cloud" to offload the current taskEscalating a local task that's grown too big — context carries over
GitHubComment @codex on an issue or PRTurning a tracked issue or PR thread straight into work
CLIcodex cloud (picker) or codex cloud execScripting, automation, and staying in the terminal

The IDE route is the one worth flagging now: when a local task balloons into something long-running, you don't have to abandon it. "Run in the cloud" hands the task — with its context — to a cloud environment, lets you monitor and ask follow-ups without leaving the editor, and then apply the resulting diffs locally. The local-to-cloud handoff (and back) is covered fully in the IDE lesson; here we focus on the CLI route, because it's the most scriptable.

Note

Same task, many windows

Because all surfaces share one account, a task you launch from the CLI shows up on the web dashboard and can be steered from mobile. You're not choosing a kind of task — only the window you start it from.

Delegating from the CLI: `codex cloud`

The terminal is the most precise way to delegate, because every option is explicit. Two commands cover it.

codex cloud with no subcommand opens an interactive picker — the easiest way to browse environments and recent tasks and start one by hand:

bash
codex cloud

codex cloud exec submits a task directly — ideal for scripts and one-liners:

bash
codex cloud exec --env ENV_ID --attempts 3 "Summarize open bugs and propose fixes"

The pieces that matter:

PartMeaning
--env ENV_IDRequired. Which cloud environment to run in. Run codex cloud (the picker) to list the IDs you've configured.
--attempts 1-4Best-of-N. Ask Codex to run up to 4 independent attempts at the same task in parallel, so you can pick the best result. Range is 1 to 4.
QUERY (positional)The task prompt itself. Omit it to be prompted interactively.

Best-of-N is the cloud's superpower. Locally, you get one shot per run; in the cloud, --attempts 3 spins up three isolated containers working the same brief at once and lets you compare diffs and keep the strongest. For genuinely hard problems where the first solution is often not the best, that parallelism is exactly what you're paying the cloud for.

Because this is the same auth as the rest of the CLI, no extra login is needed — your ChatGPT sign-in or API key already authorizes cloud tasks.

Tip

Write a complete brief, not a chat opener

Cloud tasks don't pair with you turn by turn, so the prompt has to stand on its own. Use the four-element template: Goal (what to change), Context (files, errors, docs), Constraints (standards, what not to touch), and Done-when (the condition that means it's finished). A vague brief wastes a whole background run.

Inspecting tasks and bringing diffs home

Delegating is half the loop; collecting the result is the other half. Two commands close it.

codex cloud list shows your recent cloud tasks — handy for scripting, dashboards, or just remembering what you fired off:

bash
codex cloud list --env ENV_ID --limit 10 --json
FlagMeaning
--env ENV_IDFilter to one environment
--limit 1-20How many tasks to return (max 20)
--cursor STRINGPagination cursor from a previous request
--jsonMachine-readable output for scripts

The --json output includes fields like id, url, title, status, updated_at, environment_label, summary, and is_review — enough to build your own "what's running" view.

When a task finishes, you pull its changes into your local working tree with codex apply (alias codex a), passing the task's ID:

bash
codex apply TASK_ID      # or: codex a TASK_ID

That lands the cloud diff on your machine so you can run it, test it, and finish it locally — the cloud did the heavy lifting, and you take it over the last mile. The mental flow is a clean delegate-and-collect loop:

text
codex cloud exec  ──▶  task runs in cloud container
        │                       │
        ▼                       ▼
   codex cloud list  ◀──  monitor status
   codex apply TASK_ID  ──▶  diff in your working tree  ──▶  test & finish locally

Example

A full delegate-and-collect cycle

  1. codex cloud exec --env ci-env --attempts 2 "Migrate the date utils to Temporal; keep all tests green" → 2) grab a coffee; check codex cloud list --env ci-env --limit 5 → 3) when it's done, codex apply <task-id> to land the better attempt locally → 4) run the suite yourself and open or amend the PR.

From task to pull request

Cloud tasks don't just leave a diff floating in a container — they're built to feed your normal review workflow. After a task runs, Codex creates a pull request directly in the connected GitHub repo, and you review the change in the cloud diff view before it ever touches main.

This is why the GitHub connection is a prerequisite, not a nicety: it's what lets a background task end as a reviewable PR on a branch instead of an orphaned set of edits. Your options from there:

  • Review in the cloud diff view — read the file-change diff Codex produced, right where the task ran.
  • Open the PR — Codex pushes a branch and opens the pull request in the connected repo; review it like any teammate's.
  • Pull it down to testgit fetch and git checkout the branch (or codex apply TASK_ID) to run it locally before approving.

The result is that delegation slots into the process you already trust: a human reviews a diff and a PR before anything merges. The agent did the work in isolation; the gate is still your review. (Automated code review — where @codex reviews other people's PRs — is a separate capability covered in its own lesson; here, the PR is the output of your delegated task.)

Key insight

The PR is the handoff, not the merge

A finished cloud task gives you a branch and a pull request — a proposal, not a fait accompli. Nothing reaches your default branch until you review the diff and merge it yourself. Delegation widens your throughput without removing the human gate.

Local or cloud? A rule of thumb

Both surfaces run the same agent, so the choice is about the shape of the work, not its difficulty.

Stay local when the work is interactive, latency-sensitive, or control-heavy — you want to watch each turn, steer mid-flight, iterate in seconds, or you're exploring and don't yet know what "done" looks like. The tight feedback loop is the point.

Go to the cloud for heavy, fire-and-forget work — long migrations, deep cross-cutting refactors, or parallel batches where you want several independent tasks (or several attempts at one hard task) running at once while you do something else. You're trading immediacy for throughput and a clean, isolated environment.

Lean localLean cloud
Interactive, turn-by-turn steeringFire-and-forget background work
Latency-sensitive — you want answers in secondsLong-running — minutes to much longer is fine
Exploratory; "done" is still fuzzyWell-specified brief with a clear done-when
One thing at a time, under close watchParallel batches or best-of-N attempts
Needs your local environment / uncommitted stateSelf-contained, reproducible in a fresh container

Two practical constraints to plan around. First, local messages and cloud tasks share one rolling 5-hour usage window (plus weekly limits) — delegating to the cloud spends from the same budget as local work, so it's not "free" headroom. Second, cloud access is included with Plus, Pro, Business, Edu, and Enterprise plans; Enterprise workspaces may need admin setup first. Both the window mechanics and the plan list are volatile — confirm them live.

Watch out

Cloud isn't a separate budget

Local and cloud draw from the same rolling 5-hour usage window (and weekly limits). Firing off four best-of-N attempts is convenient but spends real allowance — batch deliberately. Exact per-plan numbers rotate; check developers.openai.com/codex/pricing.

Try it: Delegate a real task to the cloud and bring it home

Goal: run the full delegate-and-collect loop end to end. 1) Confirm access. You need a plan that includes Codex cloud (Plus/Pro/Business/Edu/Enterprise) and a GitHub account connected at chatgpt.com/codex; verify your environment exists by running codex cloud (the picker) and noting an ENV_ID. 2) Write a complete brief. Pick a small, well-scoped task in one of your repos and write it with the four-element template — Goal, Context, Constraints, Done-when — because the cloud won't pair with you to fill gaps. 3) Delegate with best-of-N. Run codex cloud exec --env ENV_ID --attempts 2 "<your brief>" so two isolated containers race the same task. 4) Monitor. While it runs, do something else, then check progress with codex cloud list --env ENV_ID --limit 5 (add --json and notice the status and url fields). 5) Bring it home. When it's done, run codex apply <TASK_ID> (or codex a <TASK_ID>) to land the better attempt in your working tree; run your test suite locally to confirm. 6) Review the PR. Open the pull request Codex created in the connected repo and read the diff in the cloud diff view — confirm the human review gate is intact. 7) Reflect in three sentences: Was this task better suited to cloud than local, and why? Did best-of-N produce meaningfully different attempts? And how did the shared 5-hour usage window factor into your decision to delegate? This builds the core instinct of the module: delegate heavy, well-specified work to isolated containers, then collect and review the diff like a teammate's PR.

Key takeaways

  1. 1Codex cloud is the same agent relocated to an isolated sandbox container — it clones your repo at a branch/commit and works there, in the background and in parallel, while you keep coding. Entry point: chatgpt.com/codex with a connected GitHub account.
  2. 2Five entry points delegate the same kind of task: ChatGPT web, mobile (preview), the IDE's "Run in the cloud", a GitHub `@codex` comment, and the CLI.
  3. 3Delegate from the CLI with `codex cloud` (interactive picker) or `codex cloud exec --env ENV_ID "<prompt>"`; `--env` is required and `--attempts 1-4` runs best-of-N parallel attempts so you can keep the best.
  4. 4Inspect tasks with `codex cloud list` (`--env`, `--limit 1-20`, `--json`) and bring a finished diff into your working tree with `codex apply TASK_ID` (alias `codex a`) to test and finish locally.
  5. 5After a task, Codex opens a pull request in the connected repo; review the diff in the cloud diff view — the human review gate stays in place before anything merges.
  6. 6Rule of thumb: local for interactive, latency-sensitive, control-heavy work; cloud for heavy fire-and-forget jobs and parallel batches. Local and cloud share one 5-hour usage window; cloud is included with Plus/Pro/Business/Edu/Enterprise.

Quiz

Lock in what you learned

Check your understanding

0 / 4 answered

1.What most accurately describes how Codex cloud executes a delegated task?

2.You want to delegate a hard refactor from the terminal and have Codex try three independent solutions in parallel so you can keep the best. Which command is correct?

3.A delegated cloud task has finished. You want its changes in your local working tree so you can run the tests yourself before approving. What do you run?

4.A teammate says: 'I'll just push everything to Codex cloud since it's free background compute that doesn't count against my usage.' What's the key correction?

Go deeper

Hand-picked sources to keep learning