Codex, under rules it can't turn off
To run OpenAI's Codex CLI on Linux under rules it cannot switch off, run it under Tego with one of the repository's Codex contracts. Codex's own sandbox (workspace-write is the default mode in OpenAI's docs) limits writes to the workspace and turns the network off, and once on, the kernel enforces it. But whether it is on is a setting in Codex's own configuration, and one flag removes it. Tego enforces a contract from outside Codex instead: the Linux kernel and Tego's supervisor decide which files Codex may write, which programs it may run and which hosts it may reach, and each run leaves a record.
For the bigger picture, read AI agent security on Linux. We make Tego; every claim about Codex below links OpenAI's own docs, read on 6 November 2026.
What does Codex's own sandbox limit?
On Linux, Codex "uses bwrap plus seccomp by default" (agent approvals and security). Its modes, in OpenAI's words:
| Mode | What OpenAI's docs say |
|---|---|
read-only |
"The agent can inspect files, but it can't edit files or run commands without approval." |
workspace-write |
"The agent can read files, edit within the workspace, and run routine local commands inside that boundary." Network is off unless network_access = true is set. Inside writable roots, .git stays read-only, and so do .agents, .codex and .aws when they exist as directories. |
danger-full-access |
"The agent runs without sandbox restrictions. This removes the filesystem and network boundaries." |
Sources: Sandbox and agent approvals and security.
What does it leave open?
- Reads. The sandbox page says the agent "can read files", and the approvals page says the sandbox limits what Codex can touch, typically to the current workspace. Neither page says whether reads outside the workspace are blocked, and neither names
~/.sshor.envfiles as off limits. - The switch.
sandbox_mode = "danger-full-access"inconfig.toml, or the--dangerously-bypass-approvals-and-sandboxflag (--yolo), removes the sandbox. OpenAI marks the flag "not recommended". - Machines where bubblewrap cannot start. The docs say Codex needs
bwrap, or a bundled helper that "requires support for unprivileged user namespace creation", and say that some distributions restrict them through AppArmor, with thebwrapAppArmor profile as the fix they prefer. - Containers are not a full answer either. OpenAI's docs: "a malicious project can exfiltrate anything available inside the devcontainer, including Codex credentials."
Why does Tego turn Codex's sandbox off?
Because Codex's sandbox cannot start inside Tego's. Under a Tego contract, Codex runs inside Tego's Landlock domain, where its bubblewrap sandbox cannot start. Left on, every command the model asks for fails with error building bubblewrap command: Permission denied (os error 13) (OPERATIONS.md). So Tego's Codex contracts set sandbox_mode = "danger-full-access" and approval_policy = "never" in the config.toml that Codex reads, and the contract takes the sandbox's place: its rules limit what Codex touches, and its ask folders take the place of Codex's approvals.
That sounds backwards, so here is the trade. Codex's sandbox is strong once on, but it is switched on and off in Codex's own configuration and command line. Tego's rules sit outside Codex, in a compiled contract that the agent under it cannot edit. Some of those rules are kernel enforced and some are decided best effort by Tego's supervisor, as the limits below say.
What does the Tego contract hold?
The repository ships two contracts: codex-chatgpt.yaml for a ChatGPT sign-in and codex.yaml for an API key. The API key one, as written in examples/agents/codex.yaml:
- Writes: only
./work/in the project, plus/dev/null, the terminal devices and a Codex home that Tego makes for the run. A write under./held/waits until you runtego approve(ortego deny); if nobody answers within 5 minutes, it is refused. - Reads: Codex's own sign-in, config, history and session files under
~/.codexare denied, on top of Tego's built-in list of credential paths such as~/.sshand~/.aws. - Programs: a short list (
bash,git,cat,ls,grep,sedand a few more, plus Codex's helper). Anything else is refused and recorded. - Network: none of its own. Codex's model calls go through Tego's forwarder, which records each request and response.
- Limits: 512 processes, 4 GiB of memory, and an end to a run that stalls for an hour.
The repository ran the real full-screen Codex (0.159.2, on 6 October 2026) offline under a contract like this one, with no root and a stand-in model: a read of a decoy secret was refused, git push was refused, a connection was refused, and a write was held until a second process approved it (OPERATIONS.md). The codex.yaml contract itself is compiled and its rules tested, but it has not been run with a real key.
How do you run it?
Run Claude Code and Codex under Tego has every command for both contracts. In short:
Install Tego and run
tego doctor.Give Codex a folder with a
config.tomlthat turns its sandbox off (sandbox_mode = "danger-full-access",approval_policy = "never"). For a ChatGPT plan, runcodex loginonce outside Tego and copy the sign-in into that folder; the API key contract does not take a ChatGPT login.Copy the contract, change the lines marked
CHANGE, and remove anydeny_readentry for a file you do not have, or the contract does not compile.From your project folder, make the folders the contract names (
mkdir -p work/tmp held), runtego compileon the contract, then start Codex. With an API key:Shell XDG_RUNTIME_DIR=/run/user/$(id -u) tego watch --boundary ~/contracts/codex.yaml -- codex --no-daemonWith a ChatGPT plan,
tego run ~/contracts/codex-chatgpt.yaml. Codex runs with--no-daemonbecause its shared background server would otherwise run commands outside the run; with an API key, you type the key at Codex's login screen.
The ChatGPT plan steps are in the same guide.
What does this not stop?
- The hosts you allow. With a ChatGPT sign-in, Codex talks to
chatgpt.com, so those connections are allowed by host and recorded, and their bodies are not. Tego's README: "Treat every allowed host as a way out." - Reads outside the deny lists. Tego "is not a sandbox that hides the machine". Add the paths that matter to
deny_read, as keeping agents away from SSH keys and .env files shows. - Other runs of yours, during an API key run. While it lasts, an agent in another Tego run of yours can read that run's Codex home, the typed key included. Run one agent at a time, or deny
/run/user/<uid>/tego/in the other contracts. - What an allowed program does inside its own memory, and some rules at Basic, which Tego's supervisor decides best effort. Security and known limits has the full list.
For what a Codex agent reportedly did on a server, read Asked to reboot one server, an AI agent reportedly edited /etc/fstab and started containers. For the same steps with Claude Code, read Lock down Claude Code on Linux.
Sources (5 links)
Read on 6 November 2026.
- OpenAI: Sandbox, Agent approvals and security.
- Tego: examples/agents/codex.yaml, OPERATIONS.md, README.
Read next
Lock down Claude Code on Linux in seven steps
Run Claude Code under Tego, step by step.
Asked to reboot, the agent edited /etc/fstab
Strict rules refuse key steps
Five ways to sandbox an AI agent
Sandboxes, containers, VMs and Tego, compared.