# Codex Parallel Tasks: Cloud, Worktrees or VMs

> Three ways to run Codex tasks in parallel: Codex Cloud with up to 4 attempts, the CLI with worktrees and tmux, or a VM per task. Limits and a choice table.

- URL: https://flockvm.com/learn/codex-parallel-tasks
- Last updated: 2026-11-10

There are three ways to run Codex tasks in parallel: Codex Cloud, where OpenAI gives every task its own VM; the Codex CLI on your machine, one git worktree per task; or the CLI in one VM per task that you provision. Each breaks at a different point: the plan's allowance and a fixed VM size in the cloud, branches, ports and the shared database on a laptop, setup work with your own VMs.

Every Codex fact on this page comes from OpenAI's documentation or from Codex CLI 0.166.0 (npm, 29 October 2026), read on 31 October 2026. The commands with output were run on macOS 27.2 with git 2.50.1 and tmux 3.8. We did not sign in to Codex for this page, so no agent run, duration or usage figure appears below.

| | Codex Cloud | Codex CLI, local worktrees | Codex CLI, one VM per task |
|---|---|---|---|
| Where each task runs | Its own VM at OpenAI | Your machine, one worktree each | A VM you provision |
| Resources per task | Plus: 2 vCPU, 8 GiB, 8 GiB disk. Pro, Business, Enterprise: 4 vCPU, 16 GiB, 32 GiB | Shared: your CPU, RAM and disk | Whatever you size the VM to |
| Best-of-N | Built in, 1 to 4 attempts | By hand: N worktrees, same prompt | By hand: N VMs, same prompt |
| Ports and services | Separate per task | Shared: one port 3000, one local database | Separate per VM |
| Sign-in | ChatGPT only | ChatGPT or API key | ChatGPT (device code or copied `auth.json`) or API key |
| What limits you first | Plan allowance; GitHub only; no browser use | RAM, disk, port and database clashes | Your setup time and VM bill |

## Can Codex run multiple tasks at once?

Yes, on every surface. In the ChatGPT desktop app, a new Codex chat runs in one of three places: **Local** (your project directory), **Worktree** (a git worktree on your machine) or **Cloud** ("a remote task in its own workspace from a published, reusable environment"). From the terminal, the Codex CLI starts local sessions with `codex` or `codex exec`, and cloud tasks with `codex cloud exec`.

None of them lets two agents edit the same folder safely: OpenAI's worktrees exist so Codex can "run multiple independent chats in the same project without interfering with each other." The same rule holds for Claude Code; [our guide to running Claude Code agents in parallel](/learn/run-claude-code-agents-in-parallel) covers its side.

## How do parallel tasks work in Codex Cloud?

You publish a cloud environment once (repositories, dependencies Codex installs and tests, network access, secrets), and each task starts from it. In OpenAI's words: "Each new task gets its own isolated workspace from the published environment," and "Each cloud task runs in a VM." File changes in one task don't touch the environment or the other tasks. You review each diff, ask for follow-ups, then commit or open a pull request.

From the terminal:

```bash
codex cloud exec --env <ENV_ID> --attempts 3 "Add a retry to the webhook sender"
codex cloud list --env <ENV_ID> --json
codex cloud diff --attempt 2 <TASK_ID>
codex cloud apply --attempt 2 <TASK_ID>
```

`codex cloud` is marked "[EXPERIMENTAL]" in the CLI's help. We did not run these four commands: they need a signed-in account and a published environment.

### Attempts: best-of-N in the cloud

`--attempts` runs the same task up to 4 times (default 1), and the CLI refuses a higher value before sending anything:

```text
$ codex cloud exec --env test --attempts 5 "noop"
error: invalid value '5' for '--attempts <ATTEMPTS>': attempts must be between 1 and 4

For more information, try '--help'.
```

Picking the attempt you keep, and scoring attempts with tests, is covered in [best-of-N for coding agents](/learn/best-of-n-coding-agents#does-codex-have-best-of-n).

### How big is each cloud task?

OpenAI's cloud environments page lists the default VM per task:

| ChatGPT plan | vCPUs | Memory | Disk |
|---|---|---|---|
| Plus, Edu Plus | 2 | 8 GiB | 8 GiB |
| Pro, Business, Enterprise | 4 | 16 GiB | 32 GiB |
| Edu, Edu Pro | 4 | 16 GiB | 32 GiB |

"Larger VMs and custom specifications are available for Enterprise." A task's saved VM state "is recoverable for up to seven days" after its last turn.

### What limits Codex Cloud?

- **Your plan's allowance, not a task count.** OpenAI publishes no limit on concurrent cloud tasks that we could find. It does say that "Local messages and cloud chats share your plan's usage allowance," that "Cloud tasks may use more of your allowance than local messages," and that "Weekly limits may also apply." On 31 October 2026 the pricing page lists Plus at $20 a month and Pro at $100, $200 or $500 a month; "Pro plans currently have no five-hour limit." OpenAI does not say how attempts count against the allowance.
- **ChatGPT sign-in only.** "Codex cloud requires signing in with ChatGPT." The API-key option has "No cloud-based features."
- **GitHub only.** GitLab and self-hosted GitHub Enterprise Server are listed under "Current limitations", along with computer and browser use.
- **Nothing from your machine.** "Your computer's local files, running processes, browser sign-ins, and VPN access aren't automatically transferred." Private services need Tailscale; raw TCP clients go through the environment's HTTP CONNECT proxy at `proxy:8088`.
- **A fixed size.** On Plus, a test suite that needs more than 8 GiB of RAM or 8 GiB of disk doesn't fit, whatever the number of tasks.

## How do you run Codex CLI tasks in parallel locally?

One git worktree per task, one Codex session per worktree. A worktree is a second checkout of the repository: its own files, the same `.git` history.

### With the CLI's own worktree flag

Codex CLI 0.166.0 has a flag for it. From `codex exec --help`:

```text
      --worktree
          Run the session in a new managed Git worktree
```

So each of these runs in its own checkout (not run here: it needs a signed-in Codex):

```bash
codex exec --worktree -o task-a.md "Fix the flaky date test in utils/" &
codex exec --worktree -o task-b.md "Add pagination to GET /invoices" &
wait
```

`-o` writes the agent's last message to a file. `--ephemeral` skips saving session files to disk, useful for throwaway runs.

### With git worktrees and tmux

If you want to see each session, or use interactive `codex`, make the worktrees yourself and give each one a tmux window. The git and tmux part, as we ran it in a test repository:

```text
$ git worktree add -q -b task-a ../app-task-a
$ git worktree add -q -b task-b ../app-task-b
$ git worktree list
/private/tmp/codexpar/demo/app         bcf9a6b [main]
/private/tmp/codexpar/demo/app-task-a  bcf9a6b [task-a]
/private/tmp/codexpar/demo/app-task-b  bcf9a6b [task-b]
```

Then, one window per task (Codex part not run here):

```bash
tmux new-session -d -s codex -n a -c ../app-task-a
tmux new-window -t codex -n b -c ../app-task-b
tmux send-keys -t codex:a 'codex "Fix the flaky date test in utils/"' Enter
tmux send-keys -t codex:b 'codex "Add pagination to GET /invoices"' Enter
tmux attach -t codex
```

The tmux side (layouts, logging, detaching) is covered in [Claude Code with tmux](/learn/claude-code-tmux); it works the same with Codex. Tools such as Conductor wrap this pattern in a UI: see [parallel agent orchestrators compared](/compare/parallel-agent-orchestrators). The ChatGPT desktop app's **Worktree** mode does it for you, with a setup script per new worktree and ignored files such as `.env` copied from a `.worktreeinclude` list (app-managed worktrees only, "not … Git worktrees you create yourself from the command line").

### What breaks with local worktrees?

**One branch, one worktree.** Git refuses to check out a branch twice:

```text
$ git worktree add ../app-task-a2 task-a
Preparing worktree (checking out 'task-a')
fatal: 'task-a' is already used by worktree at '/private/tmp/codexpar/demo/app-task-a'
```

**Ports.** Files are separate; the network is not. We started a server on port 3000 in the first worktree's tmux window, then the same command in the second:

```text
OSError: [Errno 48] Address already in use
```

An agent that runs `npm run dev` hits the same error, or tests against the other agent's server. Give each worktree its own port (most dev servers read a `PORT` variable or a `-p` flag).

**The database.** Two agents running migrations against the same local Postgres change each other's schema. Use one database name per worktree, or one Docker Compose project per worktree (`COMPOSE_PROJECT_NAME`).

**Disk.** Each worktree needs its own dependencies. In this site's own repository (Next.js 16.4.3), the sources take about 2 MB and `node_modules` 496 MB (`du -sh`). Four worktrees with their installs: 4 × 496 MB ≈ 2 GB. OpenAI's desktop app keeps "your most recent 15 Codex-managed worktrees" by default for this reason.

**RAM and CPU.** Every session's builds and tests share one machine; how many fit depends on your project, not on Codex.

## How do you run one Codex task per VM?

Install the CLI in a VM (`npm i -g @openai/codex`), clone the repository, sign in, run one task, push the branch. One VM per task removes the port, database and disk clashes, because nothing is shared but the git remote. It is also the setup OpenAI has in mind for its most permissive flag: `--dangerously-bypass-approvals-and-sandbox` is "Intended solely for running in environments that are externally sandboxed." Its short alias is `--yolo`: how to turn it on and what it removes is in [Codex --yolo mode](/learn/codex-yolo-mode), and what a VM still lets through is in [running coding agents with skip-permissions safely](/learn/dangerously-skip-permissions-safely).

### How do you sign in to Codex on a VM?

A VM has no browser. Three routes from OpenAI's authentication page:

- **Device code (beta):** `codex login --device-auth`, after enabling device code login in your ChatGPT security settings (or your workspace admin does).
- **Copy the login cache:** run `codex login` on your laptop, then copy `~/.codex/auth.json` to the VM. OpenAI: "Treat `~/.codex/auth.json` like a password: it contains access tokens."
- **API key:** `codex login --with-api-key` reads the key from stdin. Usage is billed at API rates, which the pricing page recommends "for automation in shared environments like CI."

Either way a credential sits inside every VM. Anything the agent runs there can read it, so use a key you can revoke, and revoke it when the batch is done.

### What limits a VM per task?

- **The allowance is still shared.** Ten VMs signed in to one ChatGPT account draw from one plan.
- **You build the plumbing.** An image with your toolchain, a way to start N copies, collect N branches and shut the VMs down. A VM that waits for your review keeps billing unless you can pause it.
- **Start time.** If a VM takes minutes to boot and install dependencies, short tasks spend more time starting than working. MicroVMs that boot in about a second, or [restore from a snapshot](/learn/firecracker-snapshot-restore), close most of that gap.

## Are parallel tasks the same as Codex subagents?

No. Subagents run inside one Codex session: the main agent spawns helpers in parallel and collects "their results in one response." They inherit the parent session's sandbox and approval settings. OpenAI recommends them for "read-heavy tasks such as exploration, tests, triage, and summarization" and warns that "agents editing code at once can create conflicts." `agents.max_concurrent_threads_per_session` in `config.toml` caps how many run at once; left unset, "Codex chooses the default." Subagents also "consume more tokens than comparable single-agent runs."

Parallel tasks are separate sessions with separate checkouts. Use subagents to split one task, and parallel tasks to run several tasks, or several attempts at one.

## Which setup should you pick?

| Your situation | Pick |
|---|---|
| Repository on GitHub, setup fits in the plan's VM, you want best-of-N without building anything | Codex Cloud, `--attempts` 2 to 4 |
| Two to four tasks, a laptop with spare RAM, no dev server or database in the loop | Local worktrees, `codex exec --worktree` or tmux |
| Tasks that start servers, run migrations or need more than the cloud VM | One VM per task |
| GitLab, private services without Tailscale, or an API key instead of ChatGPT sign-in | Local worktrees or one VM per task |
| You want to run the agent without approvals on code you don't fully trust | One VM per task, with a revocable credential |
| One task that splits into read-only research | Subagents in a single session |

Splitting, reviewing and merging the work of ten or more agents is covered in [coding agent swarms](/use-cases/coding-agent-swarms).

## Where flockvm fits

flockvm runs the third column: one [Firecracker microVM](/firecracker-sandbox) per agent, reachable over SSH about a second after start, with logs, pause and resume that keep the VM's memory, and billing per second. Sign-ups are open (Google, GitHub or an email link), with a [7-day free trial](/pricing): card required, nothing charged for 7 days, cancel anytime. It runs on one host in France (OVHcloud), which runs up to 15 `small` VMs at once, across all customers; other regions are planned. You bring your own Codex sign-in, and in this version it is stored inside the VM, so use one you can revoke. The docs' [Codex guide](/docs/agents/codex) covers the sign-in without a browser and the one-shot runs, and [Codex CLI for enterprise teams](/playbooks/codex-cli-enterprise) scripts one VM per task with a scoped key and a shared environment.

What it doesn't do yet: there is no fork, so each VM starts from its image rather than from a copy of a running one, and swarms of 10 to 20 agents are what flockvm is building next, not something it offers today. If the local worktree setup has run out of room, [start a 7-day free trial](/signup).

## Sources

- [OpenAI, Codex docs: Codex Cloud](https://learn.chatgpt.com/docs/cloud) (accessed 2026-10-31)
- [OpenAI, Codex docs: Cloud environments (VM specifications, saved state, services, current limitations)](https://learn.chatgpt.com/docs/environments/cloud-environments) (accessed 2026-10-31)
- [OpenAI, Codex docs: Codex environments (Local, Worktree, Cloud)](https://learn.chatgpt.com/docs/environments/modes) (accessed 2026-10-31)
- [OpenAI, Codex docs: Worktrees](https://learn.chatgpt.com/docs/environments/git-worktrees) (accessed 2026-10-31)
- [OpenAI, Codex docs: Local environments (setup scripts)](https://learn.chatgpt.com/docs/environments/local-environment) (accessed 2026-10-31)
- [OpenAI, Codex docs: Developer commands (codex cloud exec --attempts)](https://learn.chatgpt.com/docs/developer-commands?surface=cli) (accessed 2026-10-31)
- [OpenAI, Codex docs: Non-interactive mode (codex exec)](https://learn.chatgpt.com/docs/non-interactive-mode) (accessed 2026-10-31)
- [OpenAI, Codex docs: Pricing and usage limits](https://learn.chatgpt.com/docs/pricing) (accessed 2026-10-31)
- [OpenAI, Codex docs: Authentication (headless login, auth.json)](https://learn.chatgpt.com/docs/auth) (accessed 2026-10-31)
- [OpenAI, Codex docs: Subagents](https://learn.chatgpt.com/docs/agent-configuration/subagents) (accessed 2026-10-31)
- [npm: @openai/codex 0.166.0 (codex --help, codex exec --help, codex cloud exec --help, run on 2026-10-31)](https://www.npmjs.com/package/@openai/codex) (accessed 2026-10-31)
- [Git documentation: git-worktree](https://git-scm.com/docs/git-worktree) (accessed 2026-10-31)
