Using Sonde with applications in containers

This guide is for the case where your Qt application runs inside a Docker container, perhaps launched from your IDE, and you want an AI agent to look at it, typically when you’ve hit a bug and want help with it.

The short version:

That gives the agent a plain stdio connection: no ports, no HTTP. So it works with agents that refuse to make HTTP connections, even to localhost, and it works the same on Linux, macOS and Windows.

Everything below was tested with Docker Desktop on macOS (Apple silicon) running Debian 13 containers with Qt 6.8.2, and is checked by tests/docker_test.py. The parts specific to an IDE’s own dev-container support are marked as untested.

Set up once

1. Build the container image with what Sonde needs

examples/docker/Dockerfile is a complete development image. It builds Sonde and the demos against Debian’s Qt 6.8, runs the unit tests, and starts the acme-orders demo. The parts that matter for your own image:

RUN apt-get install -y --no-install-recommends fontconfig fonts-dejavu-core   # fonts!
RUN useradd --create-home --uid 1000 app
USER app                                    # run the app as an ordinary user
ENV LANG=C.UTF-8 \
    QT_QPA_PLATFORM=offscreen \
    SONDE_LOCAL=myapp-mcp

2. Always listen on the local socket in development builds

If the application was started without a listener, the only way to add one is to restart it, which loses the state you wanted the agent to see. So make it the default in debug builds:

#ifndef NDEBUG
    mcp.setEventBufferCapacity(50000);          // keep a long log history (see below)
    if (!mcp.listenFromEnvironment())
        mcp.listenLocal(QStringLiteral("myapp-mcp"));
#endif

A local socket opens no network port and accepts only the application’s own user, so leaving it on in development is safe. Setting SONDE_LOCAL in the image (step 1) or in your IDE’s run configuration does the same thing without a code change.

3. Label the container, or let sonde find it

IDEs and Compose often give containers generated names. sonde bridge --docker can find yours in three ways:

docker run --label sonde.app=myapp ...

4. Commit an MCP config for the project

Put this in .mcp.json at the root of your project, so every agent session there knows how to reach the application:

{
  "mcpServers": {
    "myapp": {
      "command": "build/sonde",
      "args": ["bridge", "--docker", "label=sonde.app=myapp", "myapp-mcp"]
    }
  }
}

sonde is the program Sonde builds on the host, at the top of the build directory (or in bin/ if you installed Sonde): change build/ to yours. sonde bridge --docker waits until a running container matches the label, then hands over to docker exec -i <container> sonde-bridge --wait myapp-mcp. Inside the container, --wait then waits for the application to start listening. The result is that it doesn’t matter what starts first: the agent, the container, or the application.

Claude Code asks you to approve servers from a project’s .mcp.json the first time you start claude there. Until you do, claude mcp list shows the server as “Pending approval”.

Other forms of the first argument: a container name or id instead of label=.... Options: --user USER if the application doesn’t run as the image’s default user, and --timeout SECONDS to give up instead of waiting forever. Without the script, a fixed container name works directly:

claude mcp add myapp -- docker exec -i myapp-container sonde-bridge --wait myapp-mcp

When you hit a bug

  1. Leave the application as it is. Don’t restart it or try to reproduce the bug again first: the current state is evidence.
  2. If your IDE’s debugger has stopped it, resume it. Sonde runs on the application’s GUI thread, so while the process is stopped, every tool call just waits; tested: a request sent while the process was stopped was answered as soon as it continued. The agent will see this as tools that hang or time out. A modal dialog is fine, because its event loop keeps running.
  3. Start the agent in the project and describe what you saw. For example: “the order total is wrong after I changed the quantity twice; the app is still in that state”. Mention anything you did that the application doesn’t log.

What the agent can do

Fixing and verifying

The agent edits the code; you rebuild and relaunch from your IDE as usual.

Other ways to connect

HTTP

Use this when your agent connects to HTTP servers and you’d rather not run a command. Inside a container, 127.0.0.1 is the container’s loopback, so the default binding can’t be reached through a published port. Bind all interfaces inside the container, require a token, and publish only on the host’s loopback:

docker run -e SONDE_HTTP=0.0.0.0:8765 -e SONDE_TOKEN=$(openssl rand -hex 16) \
           -p 127.0.0.1:8765:8765 ...

A socket on a bind mount (native Linux only)

On a Linux host you can put the socket in a directory shared with the host, with SONDE_LOCAL=/run/sonde/app.sock and -v /tmp/sonde:/run/sonde. Then run sonde-bridge /tmp/sonde/app.sock on the host. The host user must be the application’s user, e.g. with docker run --user $(id -u):$(id -g). I haven’t been able to test this on native Linux.

This does not work with Docker Desktop on macOS. The application can’t even create the socket: listening fails with QLocalServer::listen: Unknown error 22 (EINVAL), because the shared folder doesn’t support Unix sockets. Use docker exec instead. Docker Desktop on Windows is likely the same, but wasn’t tested.

Saved QML windows

The application in the container looks for its QML template libraries (see using.md) and its trust file inside the container. To share them with the host:

The agent saves templates through ui_template_save, so it doesn’t need to reach the container’s filesystem. (Not yet checked by tests/docker_test.py.)

Troubleshooting

Each of these was reproduced in testing.

Symptom Cause Fix
Tool calls hang, then time out The application is stopped in a debugger Resume it; waiting requests are then answered
Screenshots show empty boxes instead of text No fonts in the image (Qt logs nothing) Install fontconfig and a font package, e.g. fonts-dejavu-core
sonde-bridge: permission denied for '...' The bridge runs as a different user from the application Run it as the application’s user: --user for sonde bridge --docker or docker exec -u
sonde-bridge: waiting for '...' (... Invalid name) and nothing more The application isn’t listening on that name (yet), or the name is wrong Check SONDE_LOCAL in the container (docker exec <c> env); the socket is /tmp/<name>
sonde bridge --docker: waiting for a running container matching ... No running container passes that filter Check docker ps --filter label=... (or ancestor=...), and that the label is set
sonde bridge --docker: waiting for a running container with the socket ... With auto: no running container has the socket yet Check the application listens (SONDE_LOCAL in the container), and the socket’s name
sonde: 2 running containers have the socket ... With auto: two copies run, and sonde can’t tell which you mean Name the container, or use a filter
HTTP: Remote end closed connection without response The server listens on 127.0.0.1 inside the container Use SONDE_HTTP=0.0.0.0:<port> (with a token)
HTTP: 401 / “needs the right bearer token” Missing or wrong token Pass the token the container was started with
QLocalServer::listen: Unknown error 22 in the application’s log Socket on a bind-mounted folder with Docker Desktop Use the default socket location and docker exec
Qt warns that the locale isn’t UTF-8 The image has no UTF-8 locale set ENV LANG=C.UTF-8

Limitations

How this is tested

python3 tests/docker_test.py            # builds the image first (a few minutes)
python3 tests/docker_test.py --no-build # reuses an existing sonde-dev image

It runs sonde bridge --docker on the host, so build/sonde must be built first (cmake --build build --target sonde-cli), or SONDE_TEST_SONDE must name it. The test builds examples/docker/Dockerfile, which compiles Sonde against Debian’s Qt 6.8 and runs all the unit tests inside the container. It then checks against real containers:

It skips itself when Docker isn’t available.