Codex Sandbox: Permissions, Hosted Workers, and Costs

Choose a Codex execution boundary, fix permission failures, and budget persistent hosted workers with separate compute, disk, and OpenAI usage.

•

Published on

•

Codex Sandbox: Permissions, Hosted Workers, and Costs
Do not index
A Codex sandbox limits what the coding agent's commands can change and reach, while a hosted sandbox supplies the computer those commands run on. For a worker that continues after your laptop closes, Agent37 provides persistent gVisor or full VM instances; Codex permissions still need their own configuration. Choose the execution boundary first, then budget running time, retained disk, and OpenAI usage separately.
The practical question is what happens when a build needs internet access, a task reads credentials, or a worker restarts halfway through a change. A useful setup must handle all three without turning every failed command into a reason to grant full access.
This guide focuses on running Codex workers on infrastructure you control. Product details and calculations were checked on November 6, 2026.

Choose the right Codex sandbox boundary

There are two decisions: where the worker lives, and what commands inside that worker may do. Keeping them separate makes failures easier to diagnose.
Layer
What you choose
What you still need to manage
Codex command sandbox
Filesystem and command network permissions
Credentials, connected tools, and approved exceptions
Hosted instance
A persistent worker with allocated resources
Worker access, dependencies, lifecycle, and stored data
Application workflow
Which job runs and what counts as complete
Timeouts, retries, artifact review, and deployment authority
OpenAI's sandboxing overview describes the command boundary. It follows spawned programs, including scripts and their child processes. It does not mean a task automatically has a separate paid server, a durable workspace, or permission to deploy.
Start with the job. A repository maintenance worker may only need source files, a compiler, and selected package registries. A worker testing Docker Compose needs a runtime that can run Docker. A customer-facing service also needs separate environments for workloads that must not share data.
The useful purchasing question is therefore specific: can this environment execute my build, contain its access, and recover its files at an acceptable cost?

Set command permissions deliberately

Codex's familiar sandbox modes are read-only, workspace-write, and danger-full-access. The first two impose command restrictions; the third removes that inner boundary. Approval settings decide how requests for additional authority are handled. They are a separate control.
For an unattended job that should edit its workspace but never request an exception, the CLI supports this pattern:
codex --sandbox workspace-write --ask-for-approval never exec --json \
  "Inspect this repository, make the requested change, and run its tests."
Run it from the intended repository. never means the job cannot ask for escalation. A blocked operation can still fail, and your automation must notice that outcome. These are documented examples, not a claim that we executed a paid model task for this article.
OpenAI's non-interactive guide says codex exec defaults to read-only and that --full-auto is no longer supported. Set the required mode explicitly when migrating old scripts. JSON output makes progress and failure events available to the job controller; it does not certify that the requested change is correct.
For interactive work, on-request allows approval requests. Automatic review can handle eligible requests where configured. Neither arrangement creates an outer VM. See the approval and security reference for the current combinations.

Keep files, secrets, and network rules separate

A writable workspace is a place the agent can alter. It should not also be your collection of production credentials. Put only the checkout, necessary dependencies, and job-specific inputs there. Use narrowly scoped credentials for the actual task.
Current Codex has beta permission profiles for more precise filesystem and network rules. They can restrict reads as well as writes. However, they do not simply combine with legacy sandbox configuration: an explicit --sandbox flag or loaded sandbox_mode selects the older settings instead, subject to managed-policy requirements. Pick one configuration approach and verify which is active.
Domain rules also need enforcement. Enabling network access in a profile does not activate the command proxy. Profile domain rules require an active proxy, such as features.network_proxy = true, or applicable managed network requirements. Test a permitted destination and a deliberately blocked destination before trusting the policy.
Environment filtering is another setting. The configuration reference documents shell_environment_policy and its filters. Do not assume variables with KEY, SECRET, or TOKEN in their names disappear automatically: ignore_default_excludes defaults to true. Filtering subprocess variables also cannot hide a credential that remains in a readable file.
Finally, local command restrictions are not a universal filter for connected apps, hosted web search, or other tool transports. Those have their own controls. Review what the complete worker can access, including actions available outside its shell.

Diagnose failures before widening access

On Linux, Codex uses bubblewrap and seccomp for its command sandbox. macOS uses Seatbelt; Windows has native sandbox options, and WSL2 follows the Linux path. A hosted Linux worker therefore needs compatible host and container capabilities if you want the inner sandbox enabled.
Symptom
First check
Practical next step
Package installation cannot connect
Command network policy and outer instance egress
Permit the required registries and redirects, then retry
A build cannot write a cache
Actual cache path versus writable roots
Move the cache into the workspace or grant that specific path
A profile appears ineffective
Loaded legacy sandbox settings and active proxy
Remove conflicting configuration and retest the boundary
Bubblewrap fails before the build starts
Namespace and seccomp support
Use a compatible runtime or deliberately rely on a configured outer boundary
The gateway responds but Codex cannot work
Harness authentication and readiness
Check Codex health, not merely HTTP reachability
The CLI reference documents codex sandbox linux, macos, and windows helpers for probing command behavior. Use harmless fixtures: one allowed file, one disposable file outside the intended boundary, and known network destinations. Keep real secrets out of the test.
OpenAI permits an outer-container approach when nested sandboxing cannot work. Full access inside that container still exposes everything available there. Avoid mounting the host's home directory or Docker socket into a worker just to silence an error. Our Codex Docker guide covers the container packaging route separately.

Put the worker on the right hosted runtime

Agent37 offers standard gVisor sandboxes and full VMs. Standard instances suit workers editing repositories and waiting on models or tools. They share host resources and cannot run a Docker daemon. Choose a full VM when the job needs Docker, Compose, or its own Linux kernel.
The Codex template includes the CLI, sessions, and a chat API. It is a lean image without a browser or desktop. Authenticate with your own OpenAI account using device login, or configure an API key through the documented template flow. Agent37 does not provide managed OpenAI model usage on this template.
For example, this request creates a standard worker with explicit resources:
curl --fail-with-body https://api.agent37.com/v1/instances \
  -H "Authorization: Bearer $AGENT37_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "agent37-codex",
    "type": "default",
    "resources": { "cpu": 2, "memory": 4, "disk": 4 }
  }'
Follow the template's authentication steps before sending a task. A gateway response alone does not establish readiness: check GET /v1/health?agent=codex for healthy: true. Keep the platform provisioning key in your controller unless the worker explicitly needs infrastructure authority.
For Docker workloads, consult the VM documentation. The Ubuntu VM template includes Docker; it is a different image from the Codex template. Select or build an image with the complete toolchain you need. VM entrypoints do not run a systemd init, and durable container data belongs on the billed disk.
Agent37's instance network policy is another independent boundary. Instances have public internet access by default. Domain allowlists cover HTTPS on port 443; address rules cover other ports. Test model authentication and package downloads after applying restrictions. Blocking all outbound traffic also blocks the worker's model calls.

Calculate compute and retained disk separately

For the standard runtime, current Agent37 pricing is $0.80 per vCPU and $0.70 per GB of RAM per 730 running hours, plus $0.09 per GB of disk per 730 retained hours. VM compute is 2.5 times the standard rate; disk has the same rate.
The following examples use 2 vCPU, 4 GB RAM, and 4 GB disk retained throughout a 730-hour period. They exclude OpenAI usage and other separately billed services.
Runtime and schedule
Compute
Retained disk
Infrastructure total
Standard gVisor, 60 running hours
$0.36
$0.36
$0.72
Standard gVisor, 730 running hours
$4.40
$0.36
$4.76
Full VM, 60 running hours
$0.90
$0.36
$1.26
Full VM, 730 running hours
$11.00
$0.36
$11.36
For example, standard compute is (2 × $0.80 + 4 × $0.70) × 60 / 730, or about $0.36. The disk remains reserved for the whole period, adding another $0.36. Totals are rounded to cents, not measured benchmark results.
The Ubuntu VM defaults to 12 GB disk if you omit resources. That changes the same 730-hour VM example to $12.08. Check the actual returned allocation and leave room for dependencies, build caches, and artifacts.
An awake worker bills compute even while its CPU is idle. Stop or sleep pauses compute; retained disk continues billing. Deleting the instance ends its instance meter. The 60-hour scenario therefore requires an actual lifecycle policy, not merely a worker that receives 60 hours of tasks.

Make recovery part of the deployment

Before scheduling valuable work, prove a small job can finish, save its output, and recover after interruption. This is an acceptance checklist for your deployment, not a claim of tests performed on a purchased instance here.
First, run the build with the intended permissions and outbound rules. Confirm both a successful permitted action and a blocked action. Capture the command exit status and test output, then inspect the diff before granting any merge or deployment authority.
Next, persist the checkout and necessary state on the instance's durable volume. Agent37's create-instance documentation identifies the volume mount as the folder preserved through updates. Avoid depending on a temporary build directory elsewhere in the image.
Then test a restart with an unfinished job. Record a job identifier, current stage, and output location so a replacement process can decide whether to resume, retry, or report failure. Make repeated attempts safe before adding automatic retries.
Finally, choose availability deliberately. Auto-sleep is opt-in. Its activity detection follows instance URL traffic and exec activity; an open silent connection does not keep resetting the timer. Set the timeout for the longest expected quiet phase. Wake can fall back to a fresh boot, so write essential state to disk rather than relying on process memory.

Frequently asked questions

Does a Codex sandbox include model usage?

The command sandbox is a permission mechanism. With Agent37's Codex template, infrastructure is metered by Agent37 and model usage belongs to your connected OpenAI account. A low server bill does not cap your token spend.

Should every hosted worker use a VM?

Choose by workload. Standard gVisor is a candidate for repository work without a Docker daemon. Full VMs support workloads needing their own kernel and cost more. Test the actual build and required Codex command boundary before committing to either.

Does no approval mean no sandbox?

No. --ask-for-approval never can coexist with a restricted sandbox. It removes interactive escalation requests. Full-access modes change the technical boundary and should be evaluated separately.

Where should I start?

Create an Agent37 sandbox, choose the Codex template, and connect your OpenAI account. Start with a small repository task, verify permissions and recovery, and measure running hours before expanding the workload. The instance API provides the lifecycle controls when you are ready to automate provisioning.
Vishnu

Written by

Vishnu

Founder at Agent37, which runs managed hosting for OpenClaw and Hermes agents for 1,000+ users. Writes about what actually breaks when you leave an AI agent running.