Blog · AI agents

How to Set Up Codex CLI on Mac mini

Install OpenAI Codex CLI on a remote Mac mini, sign in without a browser, choose sandbox and approval settings, keep sessions alive in tmux and protect your keys.

Codex CLI is OpenAI's coding agent for the terminal. This guide shows how to set up Codex CLI on a Mac mini you reach over SSH, so it can work on your code while your laptop is closed.

What Codex CLI is

Codex CLI is open source under the Apache-2.0 licence at github.com/openai/codex. It runs locally, reads and edits files in your project, and runs commands inside a sandbox. The model itself runs on OpenAI's side. The repo's install notes list macOS 12 or later, 4GB of memory as a minimum and 8GB as recommended, and Git 2.23 or later as optional but useful.

Codex is a product of OpenAI. Hatmac is not affiliated with OpenAI.

Why a remote Mac mini? Your laptop sleeps, travels and runs out of battery. A dedicated Mac mini in the cloud stays on, keeps your repos and toolchains in one place, and can build Apple platform code, which a Linux box cannot. You reach it over SSH. If you have not set that up yet, start with setting up a remote Mac mini.

How to set up Codex CLI on Mac mini

SSH into the Mac and install Codex with one of the documented methods.

Standalone installer. The method the docs lead with on macOS. Running it again updates Codex.

curl -fsSL https://chatgpt.com/codex/install.sh | sh

Homebrew. Codex ships as a cask.

brew install --cask codex

npm. Needs Node.js first, for example from Homebrew.

brew install node
npm install -g @openai/codex

Stick to one method so you do not end up with two copies on your path. Check with which codex.

Sign in on a headless Mac

On first run, codex asks you to sign in. You can use a ChatGPT account, which uses your plan, or an OpenAI API key, which is billed at standard API rates. The default ChatGPT flow opens a browser. Over SSH there is no browser on the remote side, so use one of the routes the authentication docs describe for headless machines.

Device code (preferred)

Enable device code login in your ChatGPT security settings, or ask your workspace admin to allow it. Then run:

codex login --device-auth

Open the printed link on your own computer, sign in and enter the one-time code. The docs mark this flow as beta at the time of writing.

Forward the login callback over SSH

Codex listens for the login callback on port 1455. Forward it from your laptop, then sign in as usual:

ssh -L 1455:localhost:1455 you@your-mac
codex login

Open the address Codex prints in your local browser. The redirect comes back through the tunnel.

API key

For scripts and CI, the docs recommend API key login. Read the key from an environment variable rather than typing it into your shell history:

printenv OPENAI_API_KEY | codex login --with-api-key

There is also a fallback: sign in on a machine with a browser and copy ~/.codex/auth.json to the Mac mini. It works, but that file holds live tokens, so see the security section below.

Approval and sandbox modes on macOS

Codex has two separate dials. The sandbox decides what commands can touch. The approval policy decides when Codex stops to ask you. On macOS the sandbox uses Apple's built-in Seatbelt framework, so it works without extra setup.

SettingValuesWhat it means
sandbox_moderead-onlyCan inspect files, cannot edit or run commands without approval.
workspace-writeCan edit inside the workspace and run routine local commands.
danger-full-accessNo sandbox restrictions.
approval_policyon-requestWorks inside the sandbox, asks before going beyond it.
neverNever stops for approval.

The default for a folder under version control is the Auto preset: workspace-write with on-request approvals. Outside version control the docs recommend read-only. You can set it per run:

codex --sandbox workspace-write --ask-for-approval on-request

Or set sandbox_mode and approval_policy in config.toml under ~/.codex. Inside a session, /permissions changes what Codex may do, and /status shows the current settings.

Three details matter on a shared or long-running machine:

  • Network is off by default in workspace-write. Turn it on only if your tasks need it, with network_access = true under [sandbox_workspace_write].
  • Some paths stay read-only even in workspace-write, including .git and, when present, .codex and .aws inside a writable root.
  • Avoid --yolo (--dangerously-bypass-approvals-and-sandbox). The docs mark it as not recommended. On a Mac that holds your keys and SSH access, a prompt injection with full access is a real risk.

Keep sessions alive with tmux

If your SSH connection drops, a plain terminal session ends with it. tmux keeps Codex running on the Mac mini.

brew install tmux
tmux new -s codex
cd ~/code/my-app
codex

Detach with Ctrl-b then d. Reattach later with tmux attach -t codex. Use one tmux window per repository if you run several tasks.

Codex also keeps its own history. codex resume reopens a recent chat from the current repository. For unattended jobs, codex exec runs Codex non-interactively and can stream results to stdout or JSONL, which suits cron jobs and pipelines.

Before a long task, create a branch and commit. Codex works best with a clean tree, and you can review its work like any pull request. Run /init once to create an AGENTS.md with build and test instructions for the project.

Keep your keys safe

  • Treat ~/.codex/auth.json like a password. It stores tokens in plain text. Do not commit it, paste it into tickets or sync it with dotfiles.
  • Choose where credentials live. The cli_auth_credentials_store setting accepts file, keyring (the OS credential store), auto (keyring when available, file otherwise) and ephemeral (memory only, for the current process).
  • Use a separate API key per machine. If you ever cancel the Mac or suspect a leak, revoke that one key without touching the rest.
  • Lock down SSH. Use key-based login and keep the agent behind SSH. The docs advise not to expose Codex execution in untrusted or public environments.
  • Watch the web. Treat web search results as untrusted input, and keep network access off unless a task needs it.

Which Mac mini for Codex?

Because the model runs in the cloud, Codex itself needs little. The Mac's job is your toolchain: Git, package managers, test suites and, for Apple platform work, Xcode and simulators. For most single-developer work a Mac mini M4 with 16GB is a sensible start. If the agent runs Xcode builds and tests all day, or you run several agents at once, the 24GB Mac mini M6 gives more headroom.

Mac mini M4

16GB · 256GB SSD

Everyday iOS builds, CI runners and remote macOS.

from $119/mo

  • Monthly$149/mo
  • 6 months$139/mo
  • 12 months$119/mo
Order Mac mini M4

Mac mini M6

Most popular

16GB · 256GB SSD

Newer chip for faster compiles and test runs.

from $129/mo

  • Monthly$169/mo
  • 6 months$159/mo
  • 12 months$129/mo
Order Mac mini M6

Mac mini M6

24GB · 512GB SSD

More memory and storage for larger projects and caches.

from $219/mo

  • Monthly$259/mo
  • 6 months$249/mo
  • 12 months$219/mo
Order Mac mini M6

Prices in USD per month for each machine's starting configuration. More memory, storage or several machines? Ask us.

Running more than one agent? AI agents on Mac mini covers layout and isolation, and Claude Code on Mac mini shows the same setup for Anthropic's CLI. If you prefer an open-source agent with many providers, see how to install OpenCode on Mac.

Codex CLIOpenAIAI coding agentMac miniSSHtmuxsandboxsecurity