Skip to content

OpenAI Codex in DevContainers

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.

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.

OpenAI Codex requires an OpenAI API key. Pass it from your host environment:

{
"containerEnv": {
"OPENAI_API_KEY": "${localEnv:OPENAI_API_KEY}"
}
}

The feature automatically recommends the openai.chatgpt VS Code extension for integrated AI assistance within the editor.

Once inside your DevContainer, use the Codex CLI:

Terminal window
# Start an interactive session
codex
# Ask a direct question
codex "refactor this function to use async/await"
Terminal window
codex "create a REST API endpoint for user registration with validation"
Terminal window
codex "explain what the deploy.sh script does step by step"
Terminal window
codex "convert this class component to a functional React component with hooks"
  • API keys: Never commit API keys to version control. Use containerEnv with localEnv references.
  • Egress filtering: Pair with the Egress Filter feature to restrict network access to api.openai.com and other required domains.
  • Container isolation: Codex runs within the DevContainer boundary and cannot access your host filesystem beyond the mounted workspace.