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:
- Have the application always listen on a local socket in development builds (it costs nothing and opens no port).
- Label the container, and commit an MCP config that connects with
sonde bridge --docker, which runssonde-bridgeinside the container throughdocker exec. - When the bug appears, leave the application as it is, resume it if it’s stopped in the debugger, and start the agent.
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
- When you hit a bug
- What the agent can do
- Fixing and verifying
- Other ways to connect
- Saved QML windows
- Troubleshooting
- Limitations
- How this is tested
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
-
Install fonts. A minimal image has none, and Qt then draws every character as an empty box, without logging any warning. The agent’s screenshots look like the left one below, and it can’t read anything on screen:
Without fonts With fonts-dejavu-core

QT_QPA_PLATFORM=offscreenruns the GUI with no display server at all. Screenshots and input injection still work, because Sonde renders windows itself (QWidget::grab(),QQuickWindow::grabWindow()). If you do have a display set up (X11 forwarding, a VNC server), the normal platform works too.LANG=C.UTF-8stops Qt from warning at startup that the locale isn’t UTF-8.sonde-bridgemust be in the image, on thePATH, next to your application. The example image builds it from source.- An ordinary user. Sonde’s local socket only accepts connections from the
user the application runs as (and from root).
docker execruns commands as the image’sUSERby default, so they match without extra options.
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:
- By its socket:
autopicks the one running container where the application’s socket exists. It needs nothing set up, but fails if two running containers have it. - By its image:
ancestor=myapp-dev(anydocker psfilter works). - By a label, which you give it yourself:
docker run --label sonde.app=myapp ...
- Docker Compose: add
labels: ["sonde.app=myapp"]to the service. - VS Code dev containers: add
"runArgs": ["--label", "sonde.app=myapp"]todevcontainer.json. This is the documented way to passdocker runoptions, but I haven’t tested it with an IDE here.
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
- Leave the application as it is. Don’t restart it or try to reproduce the bug again first: the current state is evidence.
- 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.
- 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
- See what led up to the bug.
LogEventSourcerecords the Qt log from the moment the application starts, soevent_readshows the history from before the agent connected: warnings, the actions your application logs, and (in debug builds) the source location of each message. That’s why step 2 raises the buffer from 5000 events. - Look at the current state with
window_screenshot,object_treeandobject_inspect, without changing anything. - Read the source next to the live application. It’s working in your project, so it can connect a property value it sees to the code that set it.
- Test a theory before editing code with
object_setorobject_invoke, as in the walkthrough. This changes the live state, so ask it to inspect first if you want the original state kept.
Fixing and verifying
The agent edits the code; you rebuild and relaunch from your IDE as usual.
- When the application exits, the bridge ends. If the application is the container’s main process, the container stops too, and Docker may kill the bridge before it notices (exit status 137 rather than 0). Either way, the agent’s connection is closed.
- Reconnect the agent’s MCP server once the new build is starting. In Claude
Code that’s
/mcp.sonde bridge --dockerwaits for the new container and--waitfor the application, so you can reconnect straight away. sonde-bridge --reconnect(see agent-loop.md) doesn’t help when the container restarts: the bridge runs inside it, and stops with it. It does help when the application restarts inside a container that keeps running, for example one started with a shell as its main process. In that case, rundocker exec -i <container> sonde-bridge --reconnect myapp-mcpdirectly.- Ask the agent to repeat its reproduction steps against the new build to confirm the fix.
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 ...
-p 127.0.0.1:..., not-p 8765:8765. The latter publishes the port on every network interface of your machine.- Always set a token. Binding
0.0.0.0also makes the server reachable from other containers on the same Docker network. - Clients must send
Authorization: Bearer <token>. Withsonde, pass--tokenor setSONDE_TOKEN.
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:
- mount the checkout’s
.sonde/qml/(it usually comes with the source mount) and setSONDE_QML_LIBRARYto where it is in the container, if the build isn’t inside the checkout there; - bind-mount your trust file,
~/.config/sonde/trust.json, and setSONDE_TRUST_FILEto its path in the container, so that what you trust withsonde truston the host is what the application sees.
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
- This is attaching and investigating, not debugging. The agent can’t pause the application, step through code or read local variables. For that, it works with you and your IDE’s debugger: it can suggest where to put a breakpoint, and you report what you see.
- Don’t use the application while the agent is driving it. Your input and its synthetic events go through the same queue, and the results confuse you both.
- Root can always connect. The local socket is restricted to the
application’s user, but root in the container (
docker exec -u root) bypasses file permissions. Anyone who can rundocker execon the container can already do anything in it, so this adds no new risk.
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:
- stdio through
sonde bridge --docker, with the client started before the container; - that screenshots, clicks and log events work in the container;
- that requests wait while the application is stopped and are answered when it continues;
- HTTP with a token, published on the loopback only;
- the error for a bridge running as the wrong user.
It skips itself when Docker isn’t available.