Skip to content
← Back to Skalablog

Published article

SonarQube and OpenAI Agentic Development Guide

SonarQube and OpenAI agentic development means moving security verification into the moment an agent edits a file, not the next CI run. Sonar's guide, verify and solve cycle wires its plugin, CLI and MCP server into OpenAI's Codex coding agent so issues surface while the agent still holds context. A demo project with a planted SQL injection and a hardcoded API key shows the loop closing.

What Is SonarQube and OpenAI Agentic Development?

SonarQube and OpenAI agentic development is the practice of running code analysis inside an AI coding agent's loop rather than after it. Sonar wires its SonarQube plugin, CLI and MCP server into OpenAI Codex, the company's coding agent, so security findings reach the agent while it can still act on them.

The bottleneck has shifted. Generating code is no longer the hard part; verifying it is. Sonar reports from its own developer survey of over a thousand developers that 42% of committed code is AI-generated or AI-assisted, while 96% of developers do not fully trust it and fewer than half fully verify code before merging. No one trusts the output, yet a large volume of untrusted code reaches the codebase anyway. The vendor published both figures as survey results, not as an independent audit.

Sonar's developer content engineer Killian Carlsen-Phelan demonstrated the setup at an AI Engineer session hosted alongside OpenAI's deployment engineering team and recorded on 11 October 2026. The workflow rests on three claims about agent reliability:

  • Done means a task is complete with evidence, not just declared fixed.
  • Containment is not correctness: a sandbox limits what an agent can do, but it cannot prove a query is safe.
  • The feedback contract belongs inside the loop, so the agent can act on findings while it still has the context to act on them.

The session's framing is worth keeping in mind for the rest of this article: cheaper implementations push the bottleneck toward specification and verification, and self-critique is useful but is not an independent oracle. Agent and verifier can fail in correlated ways, so the evidence has to come from tools the agent does not control.

How the Agent-Centric Development Cycle Fits a Coding Agent

Sonar splits the agent-centric development cycle into four stages, one of which it does not own. Generation stays with whatever coding tool the developer already uses. Sonar owns guide, verify and solve, and it maps those stages onto concrete artifacts rather than advice.

  • Guide injects the agent with proper context before it builds anything: project guidelines, rules and specific architecture. Sonar says this grounding reduces token cost overall, and at enterprise scale that adds up.
  • Verify runs as soon as generation finishes, to catch security, quality and maintainability issues before they leave the workspace.
  • Solve turns a detected issue into a remediation the agent can apply in the same session, so the loop closes without leaving the terminal.

The delivery mechanism is three-part. Skills are procedures for accomplishing a task. The MCP server exposes structured tools and project context, which lets the agent read the issue list without a developer copying IDs by hand. Hooks are lifecycle checks that fire at defined points in the agent loop, and they are the natural home for things like hardcoded-secret detection.

When you wire this up, the questions Sonar recommends evaluating are concrete: can you intercept secrets before model input, how is the project grounded with rules, locations or vulnerability paths, and is the scope of a change binding while preserving behavior? Then recheck, and treat the agent as an intermediate step rather than a terminal state.

Inner Loop vs Outer Loop Verification

Moving verification into the inner loop is the change that saves time. The outer loop is the traditional CI system: write code, push to GitHub or GitLab, run the pipeline, watch a scan fail, return to the editor, fix, and push again. Each round trip costs wall-clock time and context.

The inner loop is the IDE and the agent session. Sonar's argument is that verifying code as soon as it is generated avoids the push-fail-return cycle entirely. In a normal agentic workflow with stable connectivity, the issue list becomes available inside the IDE in seconds.

The two loops are not alternatives. The demo still treats CI and human review as the core of the process. A developer without the paid analysis features can skip the in-loop hook and catch the same issue at the next pipeline run, which preserves the check but gives up the faster feedback.

Inner loopOuter loop
Where it runsIDE and agent sessionCI pipeline (GitHub, GitLab)
When it firesOn generation, edit or promptOn push
Feedback latencySeconds in a stable sessionOne pipeline round trip
Main cost of skipping itSlower feedback, more reworkFailures reach the pipeline and block merges
Who owns the final callDeveloperDeveloper and reviewer

What the Demo Project Actually Contains

The demonstration repository is a tiny Python project: about four files and under 200 lines total, with four planted defects, three security vulnerabilities and one code smell. SonarQube Cloud rated the project E, its lowest security rating, on the first scan.

The headline defect is a SQL injection path. A search_task function accepts an argument taken from user-controlled input, then interpolates it directly into a query string that is executed against the database. Anyone who controls that input controls the database. Sonar flags it as a taint flow and uses symbolic execution and taint analysis to trace how user input moves through the different files and functions down to the database call.

The second defect is a hardcoded OpenAI API key sitting in plain text in the source, the classic case of a key that should have come from an env file or a variable. Sonar reports an average remediation time of 90 days for a secret committed to a public repository, which is the interval during which automated scrapers can find and use it. The plugin also supports trying the secret-detection hook interactively, which is why the presenter prompts the agent with a fake credential.

Setting Up the Plugin, CLI and MCP Server

The setup has four wiring steps and takes minutes on a stable connection. The presenter's own provisioning script is a personal shortcut, not an official Sonar product; it creates the SonarQube Cloud project and runs the first scan. You will also need Docker running before the MCP server starts.

  1. Run the provisioning script to create the cloud project, trigger the initial scan and install the SonarQube CLI. It needs a bash shell (Git Bash works on Windows) and an exported token, which is read from the environment rather than the prompt. On a personal connection the presenter says this never takes longer than a minute.
  2. Register the marketplace with the agent. The presenter uses codex plugin marketplace add to add the SonarQube marketplace, then opens the plugin list with /plugins and installs the SonarQube entry.
  3. Authenticate the CLI with sonar auth login, which the agent session then uses for the capabilities the plugin is built on.
  4. Run the Codex integration command. It writes the secrets detection hook, an agents directive pointing at the SonarQube skills, the remaining skills and the MCP configuration.

After that, the demo exercises three tools: the secrets detection hook, a list-issues tool that surfaces SonarQube findings in the terminal, and find-and-fix on those listed issues inside the plugin.

SonarQube and OpenAI Integration: Hooks Versus Rules

SonarQube and OpenAI integration works through three different mechanisms, and the difference controls how each one can be bypassed. Hooks are lifecycle checks, the MCP server exposes tools that return project data, and rules are the individual analysis findings the agent can act on. The MCP server runs in Docker and supplies skills and project context; the CLI provisions configuration and authentication. Some requests route through an MCP skill and others through a direct CLI command, which is why both pieces are required for the full setup.

The secrets detection hook fires on prompt submission. In the demonstration, an attempt to push a commit using a fake token is blocked before the model sees it, and a request to read a file containing a secret is refused. The presenter states that no secret reaches the model context and none is written to logs. The same secret scan runs over the plugin's own skill and configuration files, not only over project source.

That boundary is narrower than it first sounds. During the question session, a participant asks whether an indirect route could reach the secret, such as writing a script that reads the file. The presenter confirms the hook is invoked on prompt submission and that a bypassed path may not trigger it. The protection covers normal prompt and tool use, not arbitrary indirection.

Agentic analysis is the post-edit hook. It fires after the agent writes or modifies any file and runs a server-side scan of the changed code, so a fix that introduces a new issue is flagged immediately. Context augmentation is the pre-task hook, and it supplies the agent with project rules and architecture before generation begins.

The failure mode this guards against is the hydra problem: you ask an agent to fix one issue and two more appear from the fix itself. The post-edit scan verifies that no new vulnerabilities came out of the change.

How the Fix Is Verified

Asking the agent to fix the SQL injection rule produces a parameterized query, and the post-edit hook then reanalyses the changed code. Sonar's rule for this pattern, rule S8702, is written specifically for AI agent workflows, on the reasoning that agents should not produce code other agents can exploit.

Two behaviours are worth noting. The hook only evaluates the code that changed, so pre-existing issues elsewhere in the file are not silently swept up in the fix; the demo shows the hook reporting an older issue in the file without trying to solve it. That scope keeps the feedback tied to the edit instead of turning one task into a refactor. If a fix introduced a new finding, the agent would iterate until the finding cleared.

The last exercise adds a new function to delete a task by ID. It goes through the same loop: context augmentation supplies relevant rules and architecture before generation, server-side verification runs after the edit, and the agent iterates if anything new appears. The same loop therefore covers both repairing existing issues and checking new work.

Which Features Require a Paid Entitlement

Secrets detection and the find-and-fix flow are available across SonarQube deployment types, including the free tier. Context augmentation and agentic analysis are the exceptions, and they depend on organizational entitlements rather than the deployment shape.

The presenter states that the plugin works with cloud, server and enterprise installations, including the free tier. That means the availability split is by feature and contract level, not by where SonarQube runs. A team on the free tier still gets the secret-blocking hook and can pull the issue list into the terminal, but loses the pre-task context injection and the automatic post-edit scan.

Where This Leaves Human Review

Human review stays in the loop in this model. Sonar's position is that self-critique is useful but is not an independent oracle, because the agent and its verifier can fail in correlated ways. The recommended posture is to seek disconfirming evidence from sources like the compiler, the test suite and the analyser rather than accept the agent's own summary. The agent should not be treated as the terminal state of a task.

That reasoning extends to sandboxes. A sandbox contains what an agent can do, but it cannot prove that a generated query is safe. The controls that matter sit at different layers, and the developer keeps ownership of intent, exceptions and the decision to ship.

Sonar's survey finding that most developers do not fully trust AI-generated code is consistent with that layered approach. The tooling reduces the verification burden, and a reviewable diff with tool evidence behind it is what the tooling is meant to produce.

FAQ

What is SonarQube and OpenAI agentic development?

It is the practice of running SonarQube analysis inside an OpenAI Codex agent session. The Sonar plugin, CLI and MCP server deliver secrets detection before the prompt reaches the model and a server-side scan after each edit.

What is Sonar's guide, verify and solve cycle?

Guide injects project rules and architecture before the agent writes code. Verify scans generated code for security, quality and maintainability issues. Solve applies remediation in the same session, so the loop closes without a CI round trip.

Does SonarQube integrate with OpenAI Codex?

Yes. Sonar publishes a Codex plugin that registers a marketplace entry, installs skills, writes an agents directive and configures the MCP server, after the SonarQube CLI has authenticated. The presenter runs it against a SonarQube Cloud project, and Sonar says it also works on server and enterprise installations.

Do the SonarQube secrets hooks always block leaked credentials?

No. The hook fires on prompt submission, so it covers normal prompt and tool use. A user who routes around that path, for example by having the agent write a script that reads a file, may not trigger it.

Which SonarQube features need a paid entitlement?

Context augmentation and agentic analysis are the two the presenter identifies as unavailable on the free tier. Secrets detection and the find-and-fix flow work across cloud, server and enterprise installations.

What defects does the demo project contain?

A Python project of fewer than 200 lines with four planted issues: three security vulnerabilities, including a hardcoded OpenAI API key and a SQL injection path, plus one code smell. The first scan rated it E.

Does the post-edit hook fix every issue in a file?

No. It analyses the changed code and reports findings from that edit, so pre-existing problems elsewhere in the file are left for a separate task rather than bundled into the fix.

What happens if an agent's fix introduces a new vulnerability?

The server-side agentic analysis hook flags the new finding and the agent continues iterating until it is resolved. A team without that entitlement catches the same issue at the next pipeline run.

Is the Sonar provisioning script an official product?

No. The presenter describes the script that creates the cloud project and runs the first scan as a personal shortcut he built to avoid clicking through the interface during a live session.

Why is a reviewable diff the definition of done?

Because a declared fix is unverifiable on its own. Sonar's definition of done is a diff a reviewer can read plus tool evidence that the change is safe, since the agent and its own verifier can fail in correlated ways.

Turning a Recorded Walkthrough Into a Written Guide

The core insight in this session is that a fix is only trustworthy when a tool outside the agent confirms it. The same problem shows up in conference talks: a full walkthrough of SonarQube and OpenAI agentic development exists as a recording, while the teams who need the wiring steps search for a written version. Skala Blog takes a YouTube URL, transcribes the video and generates an article draft you can review, so the knowledge inside a session reaches the people who look for documentation. If you have recorded material on AI coding workflows, the same route turns it into a transcript-backed article.

Source video

YouTube thumbnail: SonarQube + OpenAI: Agentic Development — Killian Carlsen-Phelan, Sonar

Source video

SonarQube + OpenAI: Agentic Development — Killian Carlsen-Phelan, Sonar

Create from this video

This article was created automatically from a new video.

Automate my channel

Turn your YouTube videos into articles

Built for creators with a backlog and no editor on staff. This page started as a video — Skalablog drafts from the transcript, you review every word, then publish on a first-party /p/{slug} page. Nothing goes live until you publish it.

Turn your videos into articles

Published with Skalablog