# Docker-in-Docker vs Socket vs Sysbox vs a VM for CI and Agents

> Use a VM per job when the code is untrusted, such as an AI agent's commands or pull requests from strangers. Privileged Docker-in-Docker hands the job every capability and the host's disks, and a mounted socket lets it control every container on the host. Sysbox runs Docker-in-Docker unprivileged, but its own docs say it isolates less than a VM.

Source: https://sandboxer.com/guides/docker-in-docker-vs-sysbox-vs-a-vm-for-ci-and-agents. Updated 2026-11-22.

**Short answer:** Use a VM per job when the code is untrusted, such as an AI agent's commands or pull requests from strangers. Privileged Docker-in-Docker hands the job every capability and the host's disks, and a mounted socket lets it control every container on the host. Sysbox runs Docker-in-Docker unprivileged, but its own docs say it isolates less than a VM.

Part of [Docker, Kubernetes and Nested VMs in a Cloud Sandbox](/guides/docker-and-virtualization-in-a-cloud-sandbox).

We tried all four in one Sandboxer sandbox. The VM played "the host", and each CI job or agent was a container on it.

## Docker-in-Docker vs socket mount vs Sysbox vs a VM

| | Privileged Docker-in-Docker | Host socket mount | Sysbox Docker-in-Docker | A VM per job |
| - | - | - | - | - |
| How the job gets Docker | `docker run --privileged docker:dind`, a second daemon inside the job | `-v /var/run/docker.sock:…`, the host's own daemon | `docker run --runtime=sysbox-runc docker:dind`, a second daemon, no `--privileged` | The VM's own daemon, as on any Linux machine |
| Job's capabilities (CapEff) | `000001ffffffffff`, all of them, as real root | `00000000a80425fb`, Docker's default set, but the daemon it drives runs as root | `000001ffffffffff`, but inside a user namespace: root maps to uid 165536 on the host | `user` has `0000000000000000`; root in the VM has root only in the VM |
| Host devices | 154 `/dev` entries, including the host disk `/dev/vda`; we mounted it and read `/home` | None in the job, but it can start a container that mounts anything | 16 `/dev` entries, no `/dev/vda` | Only the VM's own devices |
| Sees and controls other jobs | Not through Docker, but with every capability it can reach the host | Yes: it listed both neighbors and stopped one | No | No: each VM has its own kernel and daemon |
| Kernel | Host's | Host's | Host's | Its own |
| Extra setup | None | None | Install a package on the host; its installer restarts Docker | A VM (on Sandboxer, `sbx new`) |
| Inner `hello-world`: first run (pull) / second run | 827–919 ms / 369–376 ms | 657–699 ms / 306–332 ms | 941–1052 ms / 525–602 ms | 556–633 ms / 237–268 ms |
| Use it for | Your own trusted builds, if nothing else works | Your own trusted builds on a host with nothing else on it | Trusted or semi-trusted jobs that need Docker or systemd without `--privileged` | Untrusted code: agents, forks, pull requests from strangers |

Last checked: 2026-11-22, on prod. Timings are from two runs on a `default` sandbox (4 vCPU, 8 GB, AMD EPYC 9254, us-east) with Docker 29.9.0 in the VM, `docker:dind` 29.10.0 and Sysbox 0.7.1. Each first run includes pulling `hello-world`. They are wall-clock times for one container, not a benchmark.

The time differences are small. Over a CI job that runs for minutes, the start time won't decide this for you. The boundary will.

Related pages in this cluster: [Docker and KVM inside an agent sandbox](/guides/docker-and-kvm-inside-an-agent-sandbox) covers what a sandbox ships with, and [Run each GitHub Actions job in a fresh microVM](/guides/run-each-github-actions-job-in-a-fresh-microvm) wires a VM per job into a workflow. For containers vs microVMs in general, see [Container vs microVM for untrusted code](/guides/container-vs-microvm-for-untrusted-code). This page doesn't repeat them. It compares only the four ways to give a job Docker.

## What the projects themselves say

- **Docker on `--privileged`:** it "enables all Linux kernel capabilities", disables the default seccomp and AppArmor profiles, and "grants access to all host devices". "A container with `--privileged` is not a securely sandboxed process. Containers in this mode can get a root shell on the host and take control over the system." ([docker run reference](https://github.com/docker/cli/blob/master/docs/reference/commandline/container_run.md#privileged))
- **The `docker:dind` image:** "Although running Docker inside Docker is generally not recommended, there are some legitimate use cases, such as development of Docker itself." And: "`--privileged` is required for Docker-in-Docker to function properly, but it should be used with care as it provides full access to the host environment." ([image docs](https://github.com/docker-library/docs/blob/master/docker/content.md))
- **Docker on the socket:** "only trusted users should be allowed to control your Docker daemon", because you "can start a container where the `/host` directory is the `/` directory on your host". The `docker` group "grants root-level privileges to the user". ([Docker security](https://docs.docker.com/engine/security/), [post-install](https://docs.docker.com/engine/install/linux-postinstall/))
- **Sysbox:** it uses a "Linux user-namespace on all containers (i.e., root user in the container has zero privileges on the host)", and its Docker-in-Docker works "without using privileged containers or bind-mounting the host's Docker socket". It also says it "does not use VMs" and "does not (yet) provide the same level of isolation as VM-based alternatives". ([README](https://github.com/nestybox/sysbox/blob/master/README.md), [Docker-in-Docker guide](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/dind.md))

## 1. Privileged Docker-in-Docker

We started `docker:dind` with `--privileged`, waited for its daemon, timed `hello-world` inside it three times, and then looked at what the job can reach:

```bash
# dind.sh, run in the sandbox with: sudo bash dind.sh 2>/dev/null
docker run -d --privileged --name dind docker:dind >/dev/null
until docker exec dind docker info >/dev/null 2>&1; do sleep 0.2; done
echo "inner daemon: $(docker exec dind docker version --format '{{.Server.Version}}')"
for i in 1 2 3; do t=$(date +%s%N); docker exec dind docker run --rm hello-world | grep -q 'Hello from Docker' && echo "hello-world run $i: $(( ($(date +%s%N)-t)/1000000 )) ms"; done
docker exec dind sh -c 'grep CapEff /proc/self/status; echo "devices: $(ls /dev | wc -l)"; ls /dev/vda; mkdir -p /mnt/h && mount /dev/vda /mnt/h && echo "mounted the machine disk:" && ls /mnt/h/home && umount /mnt/h'
```

```text
inner daemon: 29.10.0
hello-world run 1: 827 ms
hello-world run 2: 369 ms
hello-world run 3: 360 ms
CapEff:	000001ffffffffff
devices: 154
/dev/vda
mounted the machine disk:
user
```

The job mounted the host's root disk and listed its home directories. On a shared CI runner, that disk can hold other jobs' checkouts and the runner's own credentials. Here "the host" was a throwaway VM, so the disk was that VM's, not ours.

## 2. Mounting the host's Docker socket

A second container, named `other-job-db`, stood in for another team's job. The "job" got only the socket and the official `docker:cli` image:

```bash
docker run -d --name other-job-db alpine:3.20 sleep 600
J="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker:cli"
echo "job sees:"; $J docker ps --format '{{.Names}} {{.Status}}'
$J docker stop -t 0 other-job-db
echo "after:"; docker ps -a --filter name=other-job-db --format '{{.Names}} {{.Status}}'
$J sh -c 'grep CapEff /proc/self/status'
```

```text
job sees:
priceless_wu Up Less than a second
other-job-db Up Less than a second
other-job-db
after:
other-job-db Exited (137) Less than a second ago
CapEff:	00000000a80425fb
```

The job had only Docker's default capabilities and still stopped its neighbor. It listed itself too (`priceless_wu`). Containers it starts are the host's containers, so a job could just as well start one with `-v /:/host`, the case Docker's security page warns about. Timed with the same loop from a long-running `docker:cli` job container, its `hello-world` ran on the host's daemon (Docker 29.9.0) in 657, 332 and 346 ms.

## 3. Sysbox, installed per its own docs

[Sysbox's distro table](https://github.com/nestybox/sysbox/blob/master/docs/distro-compat.md) lists Ubuntu 24.04 with a minimum kernel of 6.8 and no shiftfs needed. The sandbox runs Ubuntu 24.04.5 on kernel `6.18.56-sandboxer`. We followed the [package install guide](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/install-package.md): download the release `.deb`, check its SHA-256 against the one in the guide, remove running containers, install `jq` and the package.

```bash
curl -fsSLO https://github.com/nestybox/sysbox/releases/download/v0.7.1/sysbox-ce_0.7.1.linux_amd64.deb
sha256sum sysbox-ce_0.7.1.linux_amd64.deb
sudo apt-get install -y jq ./sysbox-ce_0.7.1.linux_amd64.deb
```

```text
9d6d5484f980d0a17f86c492c1262015c2afb66280bdb97215b79fde6a0261c5  sysbox-ce_0.7.1.linux_amd64.deb
…
Setting up sysbox-ce (0.7.1.linux) ...
The linux kernel headers package was not found. …
/usr/sbin/policy-rc.d returned 101, not running 'start sysbox-fs.service sysbox-mgr.service sysbox.service'
```

The checksum matched the guide's. The install worked, and the installer added `sysbox-runc` to Docker's runtimes. It didn't start the services, because the sandbox image blocks service starts during package installs (that's the `policy-rc.d` line). One `sudo systemctl start sysbox` fixed it: `sysbox`, `sysbox-mgr` and `sysbox-fs` all reported `active`. The kernel headers warning didn't matter for Docker-in-Docker.

Then the same `docker:dind` image, with Sysbox's runtime and without `--privileged`:

```bash
# run as root (sudo bash), like dind.sh
docker run -d --runtime=sysbox-runc --name sysdind docker:dind >/dev/null
# then wait for the inner daemon and time hello-world three times, as in dind.sh above
docker inspect sysdind --format 'privileged={{.HostConfig.Privileged}} runtime={{.HostConfig.Runtime}}'
docker exec sysdind sh -c 'grep CapEff /proc/self/status; echo "uid_map: $(cat /proc/self/uid_map)"; echo "devices: $(ls /dev | wc -l)"; ls /dev/vda 2>&1'
ps -o user= -p $(docker inspect -f '{{.State.Pid}}' sysdind)
```

```text
inner daemon: 29.10.0, storage: overlayfs
hello-world run 1: 941 ms
hello-world run 2: 525 ms
hello-world run 3: 533 ms
privileged=false runtime=sysbox-runc
CapEff:	000001ffffffffff
uid_map:          0     165536      65536
devices: 16
ls: /dev/vda: No such file or directory
165536
```

The inner daemon reported every capability, but in its own user namespace: uid 0 in the job is uid 165536 on the host, which is how the host's `ps` showed it. It had 16 device nodes and no host disk. That is a big step up from `--privileged`. It still shares the host's kernel, and Sysbox says plainly that it isn't a VM.

## 4. A VM per job

Inside the sandbox, Docker is just Docker. The agent runs as `user` with no capabilities, in the `docker` group, so it can run containers without `--privileged` or anyone's socket:

```bash
for i in 1 2 3; do t=$(date +%s%N); docker run --rm hello-world 2>/dev/null | grep -q 'Hello from Docker' && echo "hello-world run $i: $(( ($(date +%s%N)-t)/1000000 )) ms"; done
echo "whoami: $(whoami), groups: $(id -nG)"; grep CapEff /proc/self/status; echo "virt: $(systemd-detect-virt)"
```

```text
hello-world run 1: 556 ms
hello-world run 2: 237 ms
hello-world run 3: 240 ms
whoami: user, groups: user sudo docker kvm systemd-journal
CapEff:	0000000000000000
virt: kvm
```

The `docker` group is still root-equivalent, and `user` has `sudo`, but only inside this VM. The kernel, the daemon and the disk belong to this job alone. Delete the sandbox and they're gone. Everything above, privileged containers and the mounted socket included, ran against this VM's own kernel and disk. Each sandbox is a separate microVM with its own kernel, and no kernel is shared between sandboxes ([security](/docs/security)).

## Which one should you pick?

- **An AI agent, or pull requests from people you don't know:** a VM per job. That's the only option here where the job doesn't share a kernel with other jobs.
- **Your own builds on runners you own, and nothing else runs there:** a socket mount or privileged Docker-in-Docker both work. Assume the job is root on the runner, and throw the runner away after the job.
- **Many semi-trusted jobs on one host, Docker needed, no VMs:** Sysbox. It removes `--privileged` and the socket. It doesn't remove the shared kernel.
- **Inside a VM per job, a pipeline that already uses `docker:dind`:** it works there too, privileged or under Sysbox. Inside a throwaway VM, privileged only exposes that VM.

## Copy-paste: compare all four in one sandbox

Install the CLI with `curl -fsSL https://sandboxer.com/install | sh` and sign in with `sbx login`. Then paste this. It creates a `default` sandbox with none of your secrets and installs Sysbox 0.7.1 in it. It runs `hello-world` twice each through privileged Docker-in-Docker, Sysbox Docker-in-Docker, a socket mount and the VM's own Docker, prints what each can reach, and deletes the sandbox. It uses `jq` on your machine, and took 32 s for us.

```bash
id=$(sbx new --name aeo-dind-2 --type default --no-env --ttl 900 --json | jq -r 'select(.event=="ready") | .id')
sbx exec "$id" --timeout 300 "$(cat <<'EOF'
cd /tmp
# Sysbox first: its installer restarts Docker.
curl -fsSLO https://github.com/nestybox/sysbox/releases/download/v0.7.1/sysbox-ce_0.7.1.linux_amd64.deb
sudo apt-get update -qq && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq jq ./sysbox-ce_0.7.1.linux_amd64.deb >/dev/null 2>&1
sudo systemctl start sysbox
hw() { s=$(date +%s%N); "$@" run --rm hello-world 2>/dev/null | grep -q 'Hello from Docker' && printf '%s ms ' $(( ($(date +%s%N)-s)/1000000 )); }
up() { docker run -d --name "$1" "${@:2}" >/dev/null; until docker exec "$1" docker info >/dev/null 2>&1; do sleep 0.2; done; }
cap() { docker exec "$1" sh -c 'echo "CapEff $(grep CapEff /proc/self/status | cut -f2), /dev entries $(ls /dev | wc -l), /dev/vda $([ -e /dev/vda ] && echo yes || echo no)"'; }
up priv --privileged docker:dind
echo "privileged dind: $(hw docker exec priv docker; hw docker exec priv docker)| $(cap priv)"
up sysbox --runtime=sysbox-runc docker:dind
echo "sysbox dind:     $(hw docker exec sysbox docker; hw docker exec sysbox docker)| $(cap sysbox), uid 0 -> $(docker exec sysbox awk '{print $2}' /proc/self/uid_map)"
docker run -d --name job -v /var/run/docker.sock:/var/run/docker.sock docker:cli sleep 300 >/dev/null
echo "socket mount:    $(hw docker exec job docker; hw docker exec job docker)| job sees: $(docker exec job docker ps --format '{{.Names}}' | sort | tr '\n' ' ')"
docker exec job docker stop -t 0 priv >/dev/null && echo "                 job stopped its neighbor: priv is $(docker inspect -f '{{.State.Status}}' priv)"
docker rmi -f hello-world >/dev/null
echo "VM, native:      $(hw docker; hw docker)| CapEff of user $(grep CapEff /proc/self/status | cut -f2), virt $(systemd-detect-virt)"
EOF
)"
sbx delete "$id" --yes
sbx info "$id"
```

Our run on 2026-11-22 (output piped, so `sbx` printed JSON; image pull progress trimmed with `…`):

```text
privileged dind: 919 ms 376 ms | CapEff 000001ffffffffff, /dev entries 154, /dev/vda yes
sysbox dind:     1052 ms 602 ms | CapEff 000001ffffffffff, /dev entries 16, /dev/vda no, uid 0 -> 165536
socket mount:    699 ms 306 ms | job sees: job priv sysbox 
                 job stopped its neighbor: priv is exited
VM, native:      633 ms 268 ms | CapEff of user 0000000000000000, virt kvm
Unable to find image 'docker:dind' locally
…
Status: Downloaded newer image for docker:cli
{"ok":true,"type":"deletion.operation","operation":{…,"kind":"sandbox","reason":"explicit",…}}
{"event":"error","error":"Sandbox not found","code":"not_found","status":404,…}
```

The socket job saw all three containers on "the host" and stopped the privileged one. Only the privileged row could see the host's disk. The last line confirms the sandbox is gone. Plans start at $20/mo ([pricing](/pricing)).

## FAQ

### Is Docker-in-Docker with --privileged safe for CI?

Only for code you trust. Docker's own reference says a privileged container "is not a securely sandboxed process" and can take control of the host. In our test it mounted the host's disk.

### Is mounting /var/run/docker.sock safer than Docker-in-Docker?

No. The job gets fewer capabilities, but it drives the host's daemon, which runs as root. In our test it listed and stopped another job's container. Docker says the `docker` group grants root-level privileges.

### Does Sysbox work on Ubuntu 24.04?

Yes. Sysbox's own table lists 24.04 with kernel 6.8 or newer. Version 0.7.1 installed from its `.deb` on Ubuntu 24.04.5 with kernel 6.18 and ran `docker:dind` without `--privileged`. We had to start its services by hand, because the sandbox image blocks service starts during package installs.

### Is Sysbox as isolated as a VM?

No, and its README says so. It adds a user namespace and hides host devices, but the job still shares the host's kernel. Use a VM when the code is untrusted.

### Can I run docker:dind inside a Sandboxer sandbox?

Yes, privileged or under Sysbox. Both ran in our sandbox. You can also skip it and use the VM's own Docker, which was a little quicker for `hello-world` in our runs.

## Related

- [Docker, Kubernetes and Nested VMs in a Cloud Sandbox](/guides/docker-and-virtualization-in-a-cloud-sandbox)
- [Docker and KVM inside an agent sandbox](/guides/docker-and-kvm-inside-an-agent-sandbox)
- [Run each GitHub Actions job in a fresh microVM](/guides/run-each-github-actions-job-in-a-fresh-microvm)
- [Container vs microVM for untrusted code](/guides/container-vs-microvm-for-untrusted-code)
