OpenAIintermediate

How to Configure Approval and Sandbox Modes in OpenAI Codex CLI

Configure OpenAI Codex CLI approval and sandbox modes for your workflow. Learn the differences between suggest, auto-edit, and full-auto modes, and set appropriate safety levels for your environment.

7 min readUpdated January 2025

Want us to handle this for you?

Get expert help →

OpenAI Codex CLI provides granular control over how it interacts with your system through approval modes and sandbox settings. Understanding these controls is essential for balancing productivity with safety, whether you are experimenting with generated code or deploying in production environments.

Understanding Approval Modes

Approval modes determine how much autonomy Codex has when making changes to your files and executing commands. Codex CLI offers three distinct modes, each with different levels of human oversight.

Mode Comparison Table

ModeFile EditsCommand ExecutionBest For
suggestRequires approvalRequires approvalProduction work, learning, sensitive code
auto-editAuto-approvedRequires approvalDevelopment work, trusted file changes
full-autoAuto-approvedAuto-approvedCI/CD pipelines, isolated containers, demos

Suggest Mode (Default)

Suggest mode is the safest option and the default setting. Every action requires your explicit approval before execution.

Behavior:

  • Shows proposed file changes in a diff view
  • Waits for confirmation before writing any files
  • Displays commands before running them
  • Allows you to edit or reject any proposed changes

When to use:

  • Working with production code
  • Learning how Codex operates
  • Reviewing AI-generated code before applying
  • Any situation where mistakes are costly

Auto-Edit Mode

Auto-edit mode automatically applies file changes but still requires approval for shell commands. This strikes a balance between speed and safety.

Behavior:

  • Applies file edits immediately without prompting
  • Still requires approval for shell commands
  • Shows a summary of changes made
  • Allows undo via Git if needed

When to use:

  • Active development with version control
  • Trusted refactoring tasks
  • When you want faster iteration on code changes
  • Projects where you can easily revert changes

Full-Auto Mode

Full-auto mode gives Codex complete autonomy to execute both file changes and commands without any confirmation. Use this mode with extreme caution.

Behavior:

  • Applies all file edits automatically
  • Executes all shell commands without prompting
  • Operates completely autonomously
  • No human intervention in the loop

When to use:

  • Disposable development containers
  • Isolated CI/CD pipeline environments
  • Demonstration or testing scenarios
  • When you fully trust the operations being performed

Configuring Approval Modes

Command Line Flag

Set the approval mode for a single session using the --approval-mode flag:

# Use suggest mode (most restrictive)
codex --approval-mode suggest "refactor the authentication module"

# Use auto-edit mode (balanced)
codex --approval-mode auto-edit "add error handling to all functions"

# Use full-auto mode (least restrictive)
codex --approval-mode full-auto "run the test suite and fix failures"

Global Configuration

Set a default approval mode in your global config file.

Location: ~/.codex/config.toml

# Set default approval mode
approval_mode = "auto-edit"

Project-Level Configuration

Override the global setting for specific projects by creating a config file in the project directory.

Location: <project-root>/.codex/config.toml

# This project uses stricter controls
approval_mode = "suggest"

Project configuration takes precedence over global configuration, allowing you to enforce stricter controls on sensitive projects.

Sandbox Mode Configuration

The sandbox isolates Codex's operations to prevent unintended changes to your system. This is particularly important when running shell commands.

Sandbox Options

Sandbox SettingDescriptionUse Case
dockerRuns commands in a Docker containerMaximum isolation, testing untrusted code
noneCommands run directly on your systemFull system access, trusted operations

Configuring the Sandbox

In config.toml:

# Use Docker sandbox for command execution
sandbox = "docker"

# Or disable sandbox for full system access
sandbox = "none"

Via command line:

# Run with Docker sandbox
codex --sandbox docker "install dependencies and run tests"

# Run without sandbox
codex --sandbox none "deploy to production"

When to Use the Sandbox

Enable sandbox (docker) when:

  • Testing AI-generated scripts for the first time
  • Working with unfamiliar codebases
  • Running commands that could modify system state
  • In shared development environments
  • Learning or experimenting with Codex

Disable sandbox (none) when:

  • You need access to system tools not available in Docker
  • Running trusted, well-understood commands
  • Working with local services (databases, servers)
  • Performance is critical

Switching Modes During Sessions

You can change approval modes mid-session using the /mode command without restarting Codex.

# Inside an active Codex session
/mode suggest      # Switch to suggest mode
/mode auto-edit    # Switch to auto-edit mode
/mode full-auto    # Switch to full-auto mode

This is useful when you want to start conservatively and then speed up once you trust the direction of the work.

Security Best Practices

General Recommendations

  1. Start with suggest mode until you understand Codex behavior in your codebase
  2. Use version control (Git) so you can easily revert unintended changes
  3. Enable the sandbox when running commands from AI-generated code
  4. Review generated code before running it, even in auto-edit mode
  5. Never use full-auto on production systems or with sensitive data

Personal development machine:

approval_mode = "auto-edit"
sandbox = "none"

Shared team environment:

approval_mode = "suggest"
sandbox = "docker"

CI/CD pipeline (isolated container):

approval_mode = "full-auto"
sandbox = "none"

Learning and experimentation:

approval_mode = "suggest"
sandbox = "docker"

Environment-Specific Configurations

Consider maintaining different config files for different contexts:

# Development config
~/.codex/config.toml

# Strict config for production work
~/.codex/config-production.toml

# Use the production config
CODEX_CONFIG=~/.codex/config-production.toml codex "review security"

Combining Approval and Sandbox Settings

The approval mode and sandbox settings work together to create your overall safety profile:

Approval ModeSandboxSafety LevelDescription
suggestdockerMaximumAll changes confirmed, commands isolated
suggestnoneHighAll changes confirmed, full system access
auto-editdockerMediumFile changes auto-approved, commands isolated
auto-editnoneLowFile changes auto-approved, full system access
full-autodockerVery LowAutonomous but isolated
full-autononeMinimalFull autonomy, full system access

Troubleshooting

Approval Mode Not Applying

  1. Check for project-level config overriding global settings:
cat .codex/config.toml
  1. Verify your global config syntax:
cat ~/.codex/config.toml
  1. Use explicit flag to override both:
codex --approval-mode suggest "task"

Sandbox Issues

If Docker sandbox is not working:

  1. Verify Docker is installed and running:
docker --version
docker ps
  1. Check Codex has permission to use Docker:
docker run hello-world
  1. Fall back to no sandbox if Docker is unavailable:
codex --sandbox none "task"

Next Steps

Frequently Asked Questions

Find answers to common questions

Codex CLI offers three modes: 'suggest' (safest - requires approval for all actions), 'auto-edit' (approves file edits but confirms commands), and 'full-auto' (autonomous mode - executes everything without confirmation). Choose based on your trust level and use case.

Need Professional IT & Security Help?

Our team of experts is ready to help protect and optimize your technology infrastructure.