Use Codex beyond terminal chat by invoking it from scripts with the Codex CLI and the OpenAI Python SDK. Learn how the openai library powers Codex programmatically, and build small, deterministic AI-driven steps that save outputs as artifacts for developer tools and CI automation.
Overview
Syllabus
- Unit 1: Codex CLI Execution Modes
- Comparing Assistance and Execution Modes
- SVG/PNG Export Smoke Check
- Unit 2: Codex SDK Programmatic Setup
- Building a Reusable Command Runner
- Making the Test Runner Repository-Specific
- Consulting the Model on Test Failures
- Handling API Limits and Response Formats
- Persisting Results and Orchestrating the Workflow
- Unit 3: Building the Engineer Loop
- Gathering Repository State and Test Results
- Implementing the Stage 2 Patch Planner
- Applying Patches Safely with Git
- Closing the Loop with Test Verification
- Creating the Complete Audit Trail
- Unit 4: Safe Automation Patterns
- Extract File Paths from Diffs
- Validate Patches Before They Apply
- Gate Large Changes with Environment Variables
- Integrate Safety Checks into Patching Workflow