Skip to main content
External CLI Integrations
Codex CLI Integration
Integrate OpenAI’s Codex CLI for non-interactive code execution
Codex CLI Integration
PraisonAI provides integration with OpenAI’s Codex CLI for non-interactive code execution, file modifications, and structured output.Installation
Quick Start
Use as Agent Backend
Delegate an Agent’s LLM turns tocodex exec instead of the OpenAI API — uses your ChatGPT subscription.
cli_backend= is deprecated (removal in 2.0.0). Prefer runtime="codex-cli". Run praisonai doctor fix --execute to auto-migrate YAML.Backend Configuration
Thecodex-cli backend ships with this default configuration:
Backend CLI Flags
The backend builds thecodex command with these flags:
Configuration Options
Examples
Basic Execution
Full Auto Mode
Enable file modifications:Sandbox Modes
JSON Streaming Output
Structured Output with Schema
Streaming Output
As Agent Tool
As a native async agent tool
Preferred when the agent runs onagent.astart(...) (or any async entrypoint) — the tool is awaited directly on the running loop with no thread hop.
as_async_tool() was added in PraisonAI PR #4022; as_tool() still works and is now also safe to call from inside an async agent runtime.
Environment Variables
CLI Flags Used
The integration uses the following Codex CLI flags:JSON Lines Output Format
Whenjson_output=True, the output is a stream of JSON events:
Error Handling
Robustness (PR #4111)
- A subprocess
TimeoutErroris now returned asCliBackendResult(error=...)instead of escaping as an exception. - On
CalledProcessError, the CLI’s actual stderr diagnostic is surfaced (previously only the exit status was shown). - The system-prompt argument is JSON-escaped for TOML basic-string compatibility — prompts containing quotes/newlines no longer break.
- The resume shape is now
codex exec resume <id> --skip-git-repo-check ...(previouslyresumewas misplaced after--skip-git-repo-check, which failed). -m(model) and-C(cwd) are threaded through, so scheduled runs can pin a model and run in a workspace.CliSessionBinding.is_resumeis now set on the second turn of a session, so the resume branch runs instead of re-sending the system prompt every turn.
Best Practices
- Use full_auto=True only when file modifications are needed
- Use structured output for CI/CD pipelines
- Set appropriate sandbox mode based on security requirements
- Use JSON output for programmatic processing
- Set timeouts appropriate for task complexity


