class LittleGhost::Harnesses::Codex
Runs Codex with codex exec --json.
In :isolated mode Codex’s own command sandbox is disabled (--sandbox danger-full-access) because it cannot nest inside an isolating Sandbox; the LittleGhost Sandbox that runs the harness is the boundary, and OPENAI_API_KEY is the placeholder. In :native_guards mode Codex runs commands in its own sandbox (--sandbox workspace-write) without network access, and authenticates from the inherited environment, such as OPENAI_API_KEY or CODEX_API_KEY.
Approval prompts are disabled in both modes, so a command that needs more access than Codex’s sandbox allows fails instead of asking. The update check is off, MCP servers are replaced by the request’s mcp_servers, notification commands are cleared on the command line, and configuration lives under home. Other settings in a persistent home’s config.toml still apply.
defaults accepts:
:base_url-
An OpenAI-compatible Responses API base URL, for example a
Network::Facadeaddress ending in/v1. The harness registers it as a model provider on the command line. :api_key-
Placeholder sent as
OPENAI_API_KEY. A gateway replaces it. :model-
Modelused when the request does not name one. :effort-
Reasoning effort used when the request does not name one.
Codex reports token usage but not cost, so budget_usd cannot stop it. One exec usually completes a single turn that contains every command and edit, so max_turns does not bound its work either; rely on timeout.
Public Instance Methods
Source
# File lib/little_ghost/harnesses/codex.rb, line 49 def command(request) arguments = [ executable, "exec", "--json", "-C", ".", *sandbox_arguments, "-c", 'approval_policy="never"', "-c", "check_for_update_on_startup=false", "-c", "mcp_servers=#{mcp_servers(request)}", "-c", "notify=[]", "--skip-git-repo-check", "-o", File.join(home, "last-message.md") ] if defaults[:base_url] arguments.push( "-c", "model_provider=#{toml(PROVIDER)}", "-c", "model_providers.#{PROVIDER}.name=#{toml("LittleGhost")}", "-c", "model_providers.#{PROVIDER}.base_url=#{toml(defaults[:base_url].to_s)}", "-c", "model_providers.#{PROVIDER}.env_key=#{toml("OPENAI_API_KEY")}", "-c", "model_providers.#{PROVIDER}.wire_api=#{toml("responses")}" ) end model = request.model || defaults[:model] arguments.push("-m", model.to_s) if model effort = request.effort || defaults[:effort] arguments.push("-c", "model_reasoning_effort=#{toml(effort.to_s)}") if effort request.add_dirs.each { |directory| arguments.push("--add-dir", directory) } arguments.push("resume", request.session_id) if request.session_id arguments.concat(positional(prompt_with_instructions(request))) end
Returns the Codex command line for request.
Source
# File lib/little_ghost/harnesses/codex.rb, line 82 def environment(request) values = {"CODEX_HOME" => home} values["OPENAI_API_KEY"] = api_key if isolated? values end
Returns Codex’s home and, in :isolated mode, its credential placeholder. Codex exits at startup when CODEX_HOME does not exist, so it is the harness home itself, which every run creates.
Source
# File lib/little_ghost/harnesses/codex.rb, line 89 def parse_line(line, state) data = JSON.parse(line) return [] unless data.is_a?(Hash) case data["type"] when "thread.started" state.session_id = data["thread_id"] if data["thread_id"].is_a?(String) [{kind: :start}] when "item.started" then item_started(data["item"]) when "item.completed" then item_completed(data["item"], state) when "turn.completed" then turn_completed(data["usage"], state) when "turn.failed" state.status = :failed state.stop_reason = "turn_failed" [] when "error" state.stop_reason ||= "error" [] else [] end end
Parses one exec --json event.