Skip to main content

Codex

Codex is OpenAI's agentic coding CLI. HackAgent treats a locally installed Codex instance as a first-class attack target through the codex router provider.

HackAgent can launch the target in two ways:

  • directly through the Codex CLI, using codex exec
  • through Ollama, using ollama launch codex --

In both cases there is no HTTP endpoint or bridge to stand up. HackAgent shells out to a local binary and routes the exchange through the standard tracking pipeline like every other provider.

Prerequisites

  1. Install Codex CLI and confirm it runs:

    codex --version
  2. Choose how to launch the target.

    For the default Codex CLI mode, make sure codex is on your PATH.

    For the Ollama-backed mode, install Ollama and confirm it runs:

    ollama --version
  3. Optional: configure an OpenAI key for attacker/judge roles.

    The target itself authenticates through its own local Codex CLI flow. HackAgent does not need an OpenAI key to start the local target process.

    You only need OPENAI_API_KEY if you route attacker or judge models to OpenAI:

    export OPENAI_API_KEY="sk-..."

    For fully local runs, route judge/category-classifier to Ollama.

Quick Start

The fastest way is the bundled hackagent codex preset, which pre-fills the target, model, attack strategy, and a starter set of red-team goals.

h4rm3l is the default because it is the current Codex preset strategy and works well for composable prompt-obfuscation tests against coding assistants.

hackagent codex

Opens the interactive TUI with the Attacks tab pre-configured to target Codex. Edit the goals and execute.

Launch modes

Codex CLI mode

In the default mode, HackAgent launches Codex directly through the codex binary:

adapter_operational_config={
"name": "gpt-5.5",
"binary": "codex",
}

This shells out to headless Codex CLI execution. The configured model name is passed to Codex.

The equivalent CLI invocation is:

hackagent codex --no-tui

Ollama launcher mode

In Ollama mode, HackAgent launches Codex through the ollama binary:

adapter_operational_config={
"name": "llama3.2:3b",
"binary": "ollama",
}

The equivalent CLI invocation is:

hackagent codex --no-tui --binary ollama --model llama3.2:3b

This is useful when you want Codex launched against a local Ollama-backed model.

Configuration

The target is configured through adapter_operational_config:

KeyDefaultDescription
namerequiredModel name passed to the selected launcher. With binary="codex", this is passed to Codex. With binary="ollama", this is passed to Ollama.
binarycodexLocal executable used to launch the target. Use codex for Codex CLI mode or ollama for the Ollama launcher mode.
system_prompt-Override the system prompt by wrapping the prompt sent to Codex stdin.
append_system_prompt-Append extra instructions after the user task in stdin prompt composition.
max_turns-Cap the agentic loop iterations, when supported by the selected launcher.
cwd-Working directory to run the launcher in.
timeout300Per-turn timeout in seconds.
extra_args[]Additional raw launcher flags.
Prompt safety

The adversarial prompt is fed through stdin rather than argv, so text that begins with - is not misread as a CLI flag, and long prompts avoid argv length limits.

Troubleshooting

codex not found on PATH

CodexConfigurationError: Codex executable 'codex' was not found on PATH.

Install Codex CLI, or pass the full path via --binary / adapter_operational_config["binary"].

ollama not found on PATH

If you run:

hackagent codex --no-tui --binary ollama --model llama3.2:3b

make sure Ollama is installed and available on your PATH:

ollama --version

You can also pass the full path to the Ollama executable via --binary or adapter_operational_config["binary"].

Attacker/judge errors about a missing API key

This means attacker or judge routing points to OpenAI but OPENAI_API_KEY is not set.

Either export the key:

export OPENAI_API_KEY="sk-..."

or use local Ollama-backed configurations for judge/category-classifier instead.

Further Reading