What you’ll build
You will start a sandbox from thecodex template — which ships with OpenAI’s Codex CLI pre-installed — and hand Codex a coding task. Codex reads and edits code, runs commands, and executes what it writes inside the sandbox, so none of its actions touch your machine. The model can be OpenAI’s or any Novita-hosted model.
Prerequisites
- Novita API key — create one in Key Management and export it as
NOVITA_API_KEY. - A model key — an OpenAI key exported as
CODEX_API_KEYfor the Quickstart, or nothing extra if you use Novita models. - Novita Sandbox SDK — Python 3.10+ or Node.js 20+:
- Codex version — the
codextemplate comes with the Codex CLI pre-installed; nothing to install. Runcodex --versionin a sandbox to see the bundled version.
Quickstart
Create a sandbox from thecodex template, run one non-interactive task with codex exec, stream its output, and kill the sandbox.
codex exec "<prompt>" runs Codex non-interactively: it processes the prompt, prints the result, and exits, which makes it scriptable. --full-auto approves the file and command actions Codex would otherwise prompt for — use it only in an isolated sandbox like this one. --skip-git-repo-check lets Codex run outside a Git repository.How it works
Codex gets a full Linux environment inside the sandbox. You drive it with the SDK:files and git to move code in and out, commands to run Codex and anything else. The snippets below assume a sandbox created as in the Quickstart.
Execute generated code
Codex writes code and runs it in the sandbox’s shell. Its output streams back throughon_stdout / on_stderr, and the call returns the exit code.
Read and write files on a cloned repository
The most common workflow: clone a repository withsandbox.git.clone (with credentials for private repos), let Codex change it, then read the result back — here, the diff.
sandbox.files.write and sandbox.files.read; see Read and write files.
Run commands yourself
Run any command next to the agent — install dependencies before it starts, or verify its work afterwards without trusting its own report.Resume a session
Codex can continue a previous session, so you can run a multi-step workflow across several calls. Start with--json to capture the thread_id from the first event (thread.started), then pass it to codex exec resume <thread_id>.
Use Novita models
To run Codex on a Novita-hosted model instead of OpenAI, write a provider config to~/.codex/config.toml before running codex, and pass your Novita key instead of CODEX_API_KEY. Change model to switch to any model in the Novita model library. See Codex with Novita for details.
Codex supports the Responses API only, so keep
wire_api = "responses". Model usage is billed separately from sandbox runtime, at the model’s own per-token rate.Production tips
- Timeouts —
timeout(seconds;timeoutMsin JavaScript) onsandbox.createis the sandbox’s maximum lifetime; extend it while Codex works withset_timeout. Passtimeout=0tocommands.runso a long Codex turn isn’t cut off at the SDK’s default command timeout. Without long-running mode the timeout is capped by your tier (1, 3, or 4 hours); for longer runs, see Long-running sandboxes. - Pause and resume — between steps of a multi-step job, pause the sandbox instead of killing it. The repo, installed packages and Codex sessions survive, so
codex exec resumestill works after you reconnect, and CPU and RAM billing stops while it is paused. - Concurrency — each sandbox is isolated, so you can run one Codex task per sandbox in parallel — for example, one per repository or per issue. Concurrent sandboxes are capped by your account tier (5 on Free, 100 on Paid); see Quota Limits.
- Cost — sandboxes are billed per second while running. A 2 vCPU / 2 GiB sandbox costs about $0.0000260/s, so a 10-minute task is roughly $0.016 in sandbox time, plus model tokens. See Pricing.
- Keep secrets out of the sandbox — pass header-based API keys, such as your model key, as Secrets so code in the sandbox only sees a placeholder. For Git, use a short-lived token scoped to the one repository.
Troubleshooting
402: insufficient balance when creating a sandbox
402: insufficient balance when creating a sandbox
Codex refuses to run: not inside a trusted Git repository
Codex refuses to run: not inside a trusted Git repository
Codex expects to run inside a Git repository. Add
--skip-git-repo-check when running in a plain directory, or set cwd to a cloned repository.Next steps
Sandbox SDK reference
Every option for creating and managing sandboxes.
Claude Code Sandbox
Run Anthropic’s coding agent the same way.
Sandbox cookbook
Runnable Novita Sandbox examples on GitHub.
OpenCode and OpenClaw
Run open-source agents in a sandbox.