OpenAI Codex in DevContainers
Overview
Section titled “Overview”OpenAI Codex is OpenAI’s CLI tool for AI-assisted coding. It provides code generation, explanation, and editing capabilities powered by OpenAI’s models, all accessible from your DevContainer terminal.
Installation
Section titled “Installation”Add the OpenAI Codex feature to your devcontainer.json:
{ "features": { "ghcr.io/infrashift/trusted-devcontainer-features/bun:latest": {}, "ghcr.io/infrashift/trusted-devcontainer-features/openai-codex:latest": { "target_version": "latest" } }}The Bun feature is required as a dependency — OpenAI Codex is installed as a global npm package via Bun.
API Key Configuration
Section titled “API Key Configuration”OpenAI Codex requires an OpenAI API key. Pass it from your host environment:
{ "containerEnv": { "OPENAI_API_KEY": "${localEnv:OPENAI_API_KEY}" }}VS Code Extension
Section titled “VS Code Extension”The feature automatically recommends the openai.chatgpt VS Code extension for integrated AI assistance within the editor.
CLI Usage
Section titled “CLI Usage”Once inside your DevContainer, use the Codex CLI:
# Start an interactive sessioncodex
# Ask a direct questioncodex "refactor this function to use async/await"Example Workflows
Section titled “Example Workflows”Code Generation
Section titled “Code Generation”codex "create a REST API endpoint for user registration with validation"Code Explanation
Section titled “Code Explanation”codex "explain what the deploy.sh script does step by step"Refactoring
Section titled “Refactoring”codex "convert this class component to a functional React component with hooks"Security Considerations
Section titled “Security Considerations”- API keys: Never commit API keys to version control. Use
containerEnvwithlocalEnvreferences. - Egress filtering: Pair with the Egress Filter feature to restrict network access to
api.openai.comand other required domains. - Container isolation: Codex runs within the DevContainer boundary and cannot access your host filesystem beyond the mounted workspace.