This article is part of the series Developer-Basics.
TL;DR
- a Unix socket is a private communication channel between two programs on the same machine. It shows up as a special file
- a daemon is a program running in the background, often as root, waiting for requests on a socket
- whoever can talk to the Docker socket can do everything root can do. That is why the
dockergroup equals root - the SSH agent keeps your unlocked keys and signs logins for every program that can reach its socket
- a sandbox that only restricts files is not enough: a sandboxed process can ask a daemon outside of the sandbox to do the work. Sockets need their own rules
In the first article of this series, the kernel was the bouncer: every process has to ask it, and if it says “no”, there is no way around it. I also mentioned one catch: the kernel checks the process that asks. If that process can talk to another, more privileged program, that program does the work with its own rights.
This article is about exactly that “talking to another program”. On Linux, that usually happens through Unix sockets. Remember the example: your AI agent cannot read ~/.ssh/id_ed25519 inside the sandbox. But what if it can ask someone else to read it?
What Is a Unix Socket?
A Unix socket is a private connection between two programs on the same machine. One program, the service, listens on it. Other programs connect to it and send requests.
Remember “(almost) everything is a file”? Sockets are no exception. They show up as special files in the file system, for example the Docker socket:
$ ls -l /run/docker.sock
srw-rw---- 1 root docker 0 Nov 28 09:12 /run/docker.sock
ls -l lists files in the “long” format: permissions, owner, group, size, date and name. The first character of the permissions is the file type, here an s for socket (a regular file would show -, a directory d). The next nine characters are three sets of read (r), write (w) and execute (x) permissions for owner, group and others: the owner root may read and write, members of the group docker may read and write, others may do nothing. The size is 0, because a socket does not store anything. It is a connection point, not a container for data.
To connect to a socket, a process needs write permission on the socket file. So the file permissions decide who may talk to the service behind it. In this case: root and everyone in the docker group.
You can list all sockets programs are currently listening on with ss:
$ ss -xl | head
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
u_str LISTEN 0 4096 /run/docker.sock 18342 * 0
u_str LISTEN 0 4096 /run/user/1000/bus 21877 * 0
...
ss shows socket statistics. -x limits the output to Unix sockets, -l to the ones that are listening, so the ones services wait on. | head cuts the output down to the first ten lines. In the column Local Address you see the path of the socket file.
Daemons
A daemon is a program that runs in the background and waits for requests. You don’t start it yourself every time; the system starts it at boot. On most Linux systems, that is the job of systemd, the process with PID 1 you have met in the first article.
The Docker daemon is called dockerd. Let’s see who it runs as:
$ ps -o user,pid,comm -C dockerd
USER PID COMMAND
root 812 dockerd
ps lists running processes. -C dockerd selects processes by their command name, -o user,pid,comm picks the columns: the user the process runs as, its process ID (PID) and the command name. You see: dockerd runs as root.
You can also ask systemd about it:
$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; ...)
Active: active (running) since Fri 2026-11-28 09:12:03 CET; 1h ago
...
systemctl status shows whether a service is running (Active) and whether it starts at boot (enabled).
Why the Docker Group Equals Root
When you type docker run ..., the docker command does not run the container itself. It is only a client: it sends a request through /run/docker.sock to the daemon, and the daemon does the work. As root.
Now the permissions of the socket become important. Check if you are in the docker group:
$ id -nG
m1rm wheel docker
id prints information about your user: user ID, group IDs and group names. -G prints all groups, -n prints names instead of numbers.
If docker is in that list, try this:
$ cat /etc/shadow
cat: /etc/shadow: Permission denied
$ docker run --rm -v /:/host alpine cat /host/etc/shadow
root:$6$...
The first command uses cat, which prints the content of a file. /etc/shadow stores the password hashes of all users, so only root may read it, and the kernel refuses. The second command reads the very same file, without sudo. What happened?
docker run alpineasks the daemon to start a container from the smallalpineimage.--rmremoves the container again after it exits.-v /:/hostis a bind mount: it makes a folder of your machine visible inside the container. Here it is/, the whole file system, visible as/host.cat /host/etc/shadowruns inside the container, which the daemon started as root.
So you did not break any rule. You simply asked a root process to read the file for you, and it did. That is why Docker’s own documentation says that the docker group grants root-level privileges.
What This Means for Sandboxes
Now think of your AI agent again. It runs in a sandbox that denies ~/.ssh. But if it may still connect to /run/docker.sock, it can run:
docker run --rm -v ~:/h alpine cat /h/.ssh/id_ed25519
The sandbox restricts the agent. It does not restrict the Docker daemon, because the daemon was started by systemd long before the sandbox existed. The file rules are bypassed completely, without breaking anything.
Connecting to a socket is not the same as reading a file. A sandbox that only restricts file access does not necessarily cover sockets, so sockets need their own rules: which sockets may the sandboxed process connect to at all? For Docker, the safe answer for an agent is: none.
The SSH Agent
Docker is not the only daemon worth knowing. The SSH agent keeps your unlocked SSH keys in memory, so you only type the passphrase once. Programs like git or ssh ask the agent via a socket to sign a login for them. Where that socket lives is stored in an environment variable:
$ echo $SSH_AUTH_SOCK
/run/user/1000/gcr/ssh
$ ssh-add -l
256 SHA256:Xb3...k9Q m1rm@laptop (ED25519)
echo $SSH_AUTH_SOCK prints the path of the agent’s socket. On my GNOME desktop, the agent is part of the keyring (gcr), so your path may look different. ssh-add -l lists the keys the agent currently holds: the key size, its fingerprint, a comment and the key type.
The key itself never leaves the agent. Sounds safe? The catch: whoever can talk to the socket can use the key. Push to every repository you have access to, log into every server your key opens. A sandboxed agent does not need to read ~/.ssh/id_ed25519, if it can simply ask the SSH agent to sign for it.
Your Own Sockets
Have a look at /run/user/1000, where 1000 is your UID. This folder belongs to you and holds the sockets of your desktop session:
$ ls -l /run/user/1000
srw-rw-rw- 1 m1rm m1rm 0 Nov 28 09:13 bus
drwx------ 2 m1rm m1rm 60 Nov 28 09:13 gcr
srwxr-xr-x 1 m1rm m1rm 0 Nov 28 09:13 wayland-0
...
You see bus, the D-Bus session socket. Desktop programs use it to talk to each other, including the keyring that stores your passwords. wayland-0 is the connection to your display, so whoever can reach it can read your clipboard. And gcr is the folder with the SSH agent socket from above.
All of them are owned by you. So every program you start may connect to them, including your AI agent.
Big Picture Summarized
| Socket | Gives access to |
|---|---|
/run/docker.sock | root on this machine |
SSH agent socket ($SSH_AUTH_SOCK) | SSH identities: repositories, servers |
/run/user/1000/bus (D-Bus) | desktop session, including the keyring with passwords |
/run/user/1000/wayland-0 | display and clipboard |
- A Unix socket is a file-like connection point. File permissions decide who may connect.
- A daemon behind a socket does the work with its own rights, not with yours.
- The
dockergroup equals root, because the Docker daemon runs as root and does what it is asked. - A sandbox has to control sockets, not only files. Otherwise the agent asks someone outside the sandbox to do the work.
In the nono series, I will show how nono handles exactly this and which sockets I allow. The next article in this series covers the other kind of socket: the network.
Further Reading
- unix(7): everything about Unix sockets, including the permission rules
- Docker daemon attack surface: Docker’s own explanation why the
dockergroup is dangerous - Docker user namespace remapping: mapping root inside containers to an unprivileged user on the host
- SSH keys: SSH agents, ArchWiki: how SSH agents work and which ones exist
- D-Bus, ArchWiki: the message bus behind
/run/user/1000/bus
Sources
- unix(7), Linux man-pages
- ss(8), Linux man-pages
- ps(1), Linux man-pages
- systemctl(1), Linux man-pages
- Docker security, Docker documentation
- Bind mounts, Docker documentation
- ssh-agent(1), OpenBSD manual pages
- ssh-add(1), OpenBSD manual pages
- Docker, ArchWiki
- XDG Base Directory Specification, freedesktop.org:
XDG_RUNTIME_DIR, the/run/user/<UID>folder
