codex exec command runs Codex without an interactive terminal: it works
through a task on its own, prints its progress to stderr, and prints its final message to stdout.
If you run it in a Fibre sandbox, Codex gets a Linux machine of its own for the repository, its builds and its
tests, well away from your computer. Between tasks the sandbox sleeps with its memory and files, so the next task
can carry on in the same session.
This page shows the whole process, from an empty sandbox to a finished change.
Before you start, set your Fibre API key in FIBRE_API_KEY and FIBRE_API_URL=https://api.fibre.dev. For
the steps where Codex talks to its model, you also need an OpenAI API key in CODEX_API_KEY.
Start a sandbox
Install Codex
Codex is installed from npm, and the sandbox’s default image already has Node. The install takes about half a minute, which is longer than an exec allows, so it runs as a background command.Output
Output
output
Give it a repository
Response
Response
response
Run a task
By default,codex exec is only allowed to read files. Codex has a flag for running inside a machine that is
already isolated, --dangerously-bypass-approvals-and-sandbox, which lets it edit files and run commands freely.
The Fibre sandbox is exactly that kind of machine, so whatever Codex does stays inside it.
The key is passed as CODEX_API_KEY, to this one command only, as Codex’s documentation recommends. There is more
about the key below.
--json to get one JSON event per line, including every command Codex ran and every
file it changed. Or add --output-last-message <file> to save the final message in a file. With curl, follow the
command’s output in the same way as in the install step.
See what it changed
Response
Response
response
The next task, later
When Codex has finished, the sandbox goes to sleep after its idle timeout, with its memory and files saved. The next command wakes it up. Codex keeps its sessions on the sandbox’s disk, socodex exec resume --last carries on
the most recent session, with everything Codex already learned about the repository.
codex exec resume <session id>.
The API key
The agent needs your model provider’s API key, so it is worth understanding exactly where that key goes:- Only the command you give it to can see it, along with the programs that command starts. Other commands in the sandbox do not get it, Fibre does not write it into the sandbox’s files, and Fibre’s API never returns it.
- Everything Codex runs while it works can read it, including tests, install scripts and code in the repository. Treat it as visible to that repository’s code. Use a key you can revoke, with a spending limit.
- Do not put the key in the sandbox’s own environment (
envin the SDK, orenv_varsin the API, when you create the sandbox). Every command in the sandbox would then get it.
Delete it
Response
Response
response