Coding agents
Run Codex CLI in a VM
Run OpenAI's Codex CLI in a flockvm VM, preinstalled on the Agent image: sign in without a browser and run it without approvals in a disposable microVM.
The Codex CLI runs well in a flockvm VM: the VM is the external sandbox OpenAI has in mind for its most permissive mode, and nothing the agent does reaches your laptop. This guide signs it in over SSH and starts a task that keeps running after you disconnect.
Before you start
- A flockvm VM with the Agent image, the default in the New VM form. If you don't have one yet, follow the first steps of Run Claude Code in a VM. The free trial is enough:
smallanddefaultboth run Codex. - A ChatGPT plan that includes Codex, or an OpenAI API key.
The Agent image has Codex, Node.js 26, Git, tmux and Docker, and you log in as user, which has passwordless sudo. The examples below use port 22001: use your VM's port, shown in the Connect section of its page.
Check Codex
codex --version
codex mcp listCodex is installed system-wide at the version of the image's build. codex mcp list shows the playwright MCP server, set up in ~/.codex/config.toml: Codex can open pages in a headless Chromium and take screenshots. To update Codex, run sudo npm i -g @openai/codex@latest.
On the Minimal image
The Minimal image has no Codex. Create a non-root agent user as in the Claude Code guide, install Codex as root with npm install -g @openai/codex, then log in as agent and read agent wherever this page says user.
Sign in without a browser
A VM has no browser. Pick one of three routes; each leaves a credential in the VM that anything the agent runs can read, so prefer one you can revoke.
codex login --with-api-key reads the key from standard input. Send it from a file on your laptop, so it never lands in a shell history on either side:
ssh -p 22001 user@HOST 'codex login --with-api-key' < ~/openai-key.txtUsage is billed at OpenAI's API rates. Use a project key with a spend limit, and revoke it when the work is done.
In the VM, run codex login and see whether your Codex version offers a way to sign in from another device: Codex then shows a URL and a code, which you open and enter on your laptop. codex login --help lists the options your version has.
codex login --helpIf your version or your account does not offer it, use one of the other two routes.
Sign in on your laptop with codex login, then copy the login cache to the VM:
ssh -p 22001 user@HOST 'install -d -m 700 ~/.codex'
scp -P 22001 ~/.codex/auth.json user@HOST:.codex/auth.json
ssh -p 22001 user@HOST 'chmod 600 ~/.codex/auth.json'OpenAI's advice: treat ~/.codex/auth.json like a password, it contains access tokens.
Ten VMs signed in to one ChatGPT account draw from the same plan allowance.
Clone your repository
Use a deploy key for the repository, as in the Claude Code guide:
ssh-keygen -t ed25519 -N '' -C "flockvm $(hostname)" -f ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub # add it under Settings → Deploy keys on GitHub
git clone git@github.com:your-org/your-repo.gitChoose the approval and sandbox mode
Codex has its own sandbox and approval prompts. In a disposable VM, you can turn both off, or keep its sandbox and only drop the prompts:
| Flags | What Codex does | When to use it in a VM |
|---|---|---|
--dangerously-bypass-approvals-and-sandbox (alias --yolo) |
Runs every command without approvals and without its sandbox | The VM is the sandbox; the agent needs the network, Docker or system packages |
--sandbox workspace-write --ask-for-approval never |
No prompts, but writes stay inside the project, .git and .codex stay read-only, and the network stays off unless you enable it in config.toml |
You want a second layer inside the VM |
OpenAI describes the first flag as intended solely for environments that are externally sandboxed. A flockvm VM is one: a bad command breaks the VM, not your machine. It does not stop the agent from sending out what it can read, since the VM has outbound Internet access. More in running coding agents with skip-permissions safely.
Codex's flags change between versions. Run codex --help and codex exec --help in the VM to see the ones your version accepts.
Run an interactive session
Start Codex inside tmux, so it survives a dropped SSH connection:
tmux new -s codex
cd ~/your-repo
codex --dangerously-bypass-approvals-and-sandboxDetach with Ctrl-b then d. Reattach from your laptop:
Run a one-shot task
codex exec runs one task without the interactive UI. -o writes the agent's last message to a file:
cd ~/your-repo
git switch -c codex/pagination
tmux new -d -s task 'codex exec --dangerously-bypass-approvals-and-sandbox -o ~/result.md "Add pagination to GET /projects and make the tests pass" 2>&1 | tee ~/task.log'Follow it with tail -f ~/task.log, then read the summary and push:
cat ~/result.md
git push -u origin HEAD--ephemeral skips saving the session files to disk, useful for throwaway runs.
Pause, resume, delete
While you review the result, click Pause on the VM page: memory and processes are saved, billing stops. Resume brings back the same tmux session. When you are done, Delete the VM: its disk goes, and so does the copy of your Codex credential. Revoke the key or sign out the session if the agent ran code you don't trust.
A small VM costs $0.016 an hour, a default one $0.032, billed per second. Model usage counts against your ChatGPT plan or your OpenAI API bill. See Pricing.
Rolling Codex out to a team, with a key and config per environment, locked settings and Codex in GitHub Actions on flockvm runners, is the Codex CLI for enterprise teams playbook.
Next steps
One VM per Codex task, best-of-N, and cleanup.
tmux, logging, and what survives a pause.
Codex Cloud, local worktrees and one VM per task, compared.
Connect, copy files, and set up an SSH config.