codex template gives you a ready-to-use, isolated environment where Codex can read and edit code, run commands, and complete multi-step engineering tasks autonomously — without directly modifying files on your local machine.
Typical use cases:
- Autonomous coding tasks — hand Codex a prompt (e.g. “add error handling to all API endpoints”) and let it implement changes end to end.
- Working on real repositories — clone a Git repo into the sandbox and have Codex refactor, fix bugs, or add features.
- Safe, unattended automation — run the agent fully automatically inside an isolated sandbox, so file and command actions never affect your own environment.
- Multi-step workflows — start a session to plan, then resume it to carry out each step.
codex template comes with Codex pre-installed, so you can spin up a sandbox and drive Codex in just a few lines. The examples below use the SDK’s unified Novita client, create a sandbox from the codex template, run the codex CLI through commands.run, stream its output, then kill the sandbox.
Quick start
codex exec "<prompt>": the exec subcommand runs Codex non-interactively — it processes the prompt, prints the result, and exits, instead of opening an interactive session. This is what makes it scriptable inside a sandbox.--full-auto: runs Codex fully autonomously, automatically approving the file and command actions it would otherwise prompt for. Convenient in an isolated sandbox, but use it only in trusted, sandboxed environments. --skip-git-repo-check lets Codex run outside a Git repository (by default it expects to run inside one).Python
Custom Codex configuration
To make Codex use a custom LLM (custom API token, base URL, or model), write the credentials to~/.codex/auth.json and the provider settings to ~/.codex/config.toml after creating the sandbox and before running codex.
Python
Work on a cloned repository
A common workflow is to clone a Git repository into the sandbox and let Codex work on it. Usesandbox.git.clone to check out the repo (with credentials for private repos), then run codex from inside the cloned directory.
Resume a session
Codex can continue a previous session, so you can run a multi-step workflow across several invocations. Start a session with--json to capture the thread_id from the first event (thread.started), then pass it to codex exec resume <thread_id> to continue where you left off.