Repository navigation
Description
Problem
Lines cited at dcafadf. At 132ecc5, ai/mcp/server.py:1317-1330 is at :1340-1353 and :1365-1381 is at :1388-1404; the other cited lines have not moved. Paths are under src/devops_cli/ unless they start with tests/ or .devcontainer/. Paths marked docker-py are in the locked docker 7.2.0 (pyproject.toml:24).
Three commands mount a host directory as a sandbox's /workspace:
devops docker sandboxanddevops test, throughWorkloadSandboxRunner._validate_workspace_dir(docker/sandbox.py:192-214,commands/test_cmd.py:374);devops sandbox deploy, throughWorkloadSandboxEngine.validate_workspace_dir(sandbox/engine.py:191-198).
The MCP tools docker_sandbox and sandbox_deploy run the first and the last with a workspace chosen by the MCP client (ai/mcp/server.py:1317-1330, :1365-1381). They check it only for a leading hyphen (:98-104). Neither workspace check keeps engine or session sockets out of the sandbox:
- A substring test stands in for the engine-socket check. Both checks refuse a workspace only when its path contains the text
docker.sock(docker/sandbox.py:210,sandbox/engine.py:161). A workspace that is the directory holding the socket, such as/run, passes, and so does every Podman socket (podman.sock). - No runtime directory is protected.
/runis not a forbidden root (config/constants.py:202-210,core/paths.py:99-103,sandbox/engine.py:51-62,docker/sandbox.py:179-190), and nothing readsXDG_RUNTIME_DIR./var/runis a symlink to/runon current distributions.- Engine sockets live there: rootful Docker's
/run/docker.sock, rootful Podman's/run/podman/podman.sock, and the rootless sockets under$XDG_RUNTIME_DIR(docker.sock,podman/podman.sock). - Measured in the devcontainer:
/run/user/1000holds the session bus (bus), gpg-agent's socket (gnupg/S.gpg-agent) and gnome-keyring's control socket (keyring/control).DBUS_SESSION_BUS_ADDRESSisunix:path=/run/user/1000/bus(.devcontainer/devcontainer.json:46), and gnome-keyring on that bus holds the devcontainer's real secrets (tests/conftest.py:306). XDG_RUNTIME_DIRneed not sit under/run. VS Code points it under/tmp(tests/test_devcontainer.py:1511); measured in the devcontainer as/tmp/user/1000, which holds VS Code'svscode-ipc-*.sockandvscode-git-*.socksockets. So a workspace of/tmpmounts them.
- The two checks differ.
docker/sandbox.py:197compares the resolved path with its root list by exact match./etc/ssl, or a/var/runthat is a real directory, passesdevops docker sandboxanddevops test.sandbox/engine.py:115-128also refuses subpaths, throughis_forbidden_system_path.- Only the deploy path runs the traversal check (
sandbox/engine.py:96-112).
- A read-only bind mount still allows
connect()on a socket.
Who can open a mounted socket (read from the code and the engines' user mapping; not measured):
- Rootful Docker, as in the devcontainer, whose docker-in-docker engine runs inside it.
--rootlessis the default and the only mode the MCP tools use. It runs the sandbox as the host user'suid:gid(docker/sandbox.py:260-264,sandbox/engine.py:80-84).- A workspace of
/run/user/<uid>or$XDG_RUNTIME_DIRtherefore gives the sandbox the user's session bus (and gnome-keyring through it), gpg-agent and VS Code's sockets.
- Rootful Docker with
--root(devops docker sandbox,devops test). The sandbox runs as UID 0 with all capabilities dropped (sandbox/models.py:368-369). UID 0 still owns root-owned sockets, so a workspace of/rungives it the engine socket, which controls the host. - Rootless Podman or rootless Docker with
--root. Container root is the host user, so a workspace of$XDG_RUNTIME_DIRgives it the user's own engine socket and session bus. - Rootless engines with the default mapping. The sandbox runs as a subordinate UID, which cannot enter the user's
0700runtime directory. feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117 changes that mapping so that a rootless sandbox writes its workspace as the host user. That change makes these sockets reachable, so this fix lands first.
Acceptance criteria
- One check.
devops docker sandbox,devops testanddevops sandbox deployvalidate the workspace through one shared function. Each command keeps its own error type and exit code. - Refused paths. A test parametrised over both runners refuses each of these before any engine call (the client mock records no call):
/run,/run/user/1000,/run/user/1000/gnupgand/var/run;- with
XDG_RUNTIME_DIRset to a directoryrtmade bytmp_path_factory:rtitself, a directory under it, and the directory that holds it; - with
DOCKER_HOST=unix://<d>/engine/docker.sock, where<d>is undertmp_path:<d>/engine, a directory under it, and<d>; /etc/sslunderdevops docker sandbox, asdevops sandbox deployalready refuses it.
- Accepted paths. A
tmp_pathworkspace beside those directories is accepted:- with
DOCKER_HOSTunset; - with
DOCKER_HOST=tcp://192.0.2.1:2375and private networks allowed (the suite's default,tests/conftest.py:408). A tcp endpoint names no socket.
- with
- The refusal names the workspace and the protected directory.
- MCP. The
docker_sandboxandsandbox_deploytools run the shared check onworkspacebefore building the command line. Withworkspace="/run/user/1000", each raises the check's error and_run_mcp_cmdis not called. - No substring test is left.
rg -n 'docker\.sock' src/devops_cli/docker/sandbox.py src/devops_cli/sandbox/engine.pyprints nothing. - The shared constant is unchanged.
CONST_FORBIDDEN_SYSTEM_DIRSkeeps its entries, and_validate_subprocess_cwd(core/process.py:202) still accepts a directory under/run. - Test isolation.
- Today the autouse
isolate_session_busfixture setsXDG_RUNTIME_DIRtotmp_path(tests/conftest.py:304-308), and most sandbox tests usetmp_pathas the workspace (for exampletests/test_workload_sandbox.py:55-58). The fixture movesXDG_RUNTIME_DIRtotmp_path_factory.mktemp("run"), which neither holds nor sits insidetmp_path. - An autouse fixture unsets
DOCKER_HOST, so the check never reads a developer's own endpoint or runs the egress check on it. Tests that need the variable set it themselves. - With these two changes, the existing sandbox and MCP tests pass unchanged.
- Today the autouse
- Release.
- A changelog.d fragment lists the workspaces that are now refused.
- Tests are offline, start no container and build no real
DockerClient. The new tests take well under 1 s together, anduv run devops cipasses.
- Pending a person: in the devcontainer, on a build that includes this fix, run
devops docker sandbox --workspace /run/user/$(id -u) -- true, the same with--workspace "$XDG_RUNTIME_DIR", and the MCPdocker_sandboxtool withworkspaceset to/run/user/<uid>. Confirm that each is refused before any container is created, and record the results in the task file. - Pending a person: for the record, on the release before this fix, run a sandbox with workspace
/run/user/$(id -u)and the commandpython3 -c 'import socket; socket.socket(socket.AF_UNIX).connect("/workspace/bus")'. Record whether the connect succeeds. It only connects and sends no bus message.
Key questions
-
Which directories does the check protect? Proposed: three. The workspace is refused when it is, holds or sits under any of them. Paths are compared with
Path.resolve()andPath.is_relative_to:/run./var/runresolves to it where it is a symlink, and falls under the/varroot where it is a real directory.$XDG_RUNTIME_DIR, when it is set to an absolute path.- The directory of the engine's unix socket.
/run/user/<uid>, the runtime directory used when the variable is unset, lies under/run. -
Why also refuse a workspace under a protected directory? Proposed: one rule for all three directories is simpler to state and test. Subdirectories hold sockets of their own:
gnupg/S.gpg-agentandkeyring/control(measured in the devcontainer), andpodman/podman.sock. -
Where does the check get the engine socket? Proposed: from the engine's own endpoint resolution, without connecting.
- It calls
DockerEngineService.resolve_host(docker/engine.py:229-246) and normalises the result with docker-py'sdocker.utils.parse_host, the parser the client itself runs (docker-pyapi/client.py:146-148). Ahttp+unixresult names the socket, and stdliburllib.parse.urlsplitgives its path. - A tcp endpoint names no socket. Its egress check, which
client()runs anyway (docker/engine.py:253), now runs before the workspace is accepted, with the same result. - Until fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108,
resolve_hostreads onlyDOCKER_HOST, so a socket chosen through a Docker context is not followed. The usual context sockets sit under/run/user/<uid>(rootless Docker) or under the home directory (Docker Desktop), which the defaultsandbox.exclude_home_dir: truealready refuses. - When fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108 and feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117 extend the resolve step, the check follows it. Whichever item lands second keeps the check on that one step.
- It calls
-
Why not add
/runtoCONST_FORBIDDEN_SYSTEM_DIRS? Proposed: the sandbox check adds it to its own root list instead.- The constant reaches 19 other call sites in 17 modules through
is_forbidden_system_path. Among them are subprocesscwdchecks (core/process.py:202), the output writer, settings discovery and devcontainer mount parsing (commands/devcontainer.py:432). - Refusing
/runthere changes behaviour this fix does not need to change.
- The constant reaches 19 other call sites in 17 modules through
-
Does the check follow a session bus at a custom path? Proposed: no; that is out of scope.
- The bus in the devcontainer and under a systemd user session is at
/run/user/<uid>/bus, which is covered. - Following
DBUS_SESSION_BUS_ADDRESSwould need either a new direct dependency for D-Bus address parsing or a hand-written parser. The existing prefix test (commands/devcontainer.py:1265-1270) is not to be reused. - An abstract-socket bus is not on the filesystem. Abstract sockets are scoped to a network namespace, and every sandbox network mode has its own (
sandbox/models.py:52-59offers no host mode).
- The bus in the devcontainer and under a systemd user session is at
-
Why check in the MCP tools when the commands check too? Proposed: the tool refuses before it builds a command line, so the client gets the refusal as a tool error and no command runs. The check is the same function, so there is no second rule set.
Strategic alignment
- Priority P1.
- Any MCP client, including a model acting on untrusted input, can choose the sandbox workspace today.
- Under rootful Docker, the default user mapping hands such a sandbox the user's session bus and keyring when the workspace is
/run/user/<uid>. With--root, a workspace of/runhands it the engine socket. - Not measured: the second person step records the actual exposure.
- feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117's user-mapping change would widen the exposure to rootless engines, so this fix lands before it.
- Library first.
pathlib'sresolveandis_relative_toreplace the substring tests.- docker-py's
parse_hostand stdliburlsplitgive the socket path. - No new dependency, no regex and no prefix test.
- Size: small, one PR. It touches
docker/sandbox.py,sandbox/engine.py,ai/mcp/server.py,tests/conftest.pyand one new parametrised test module. - Dependencies.
- It needs nothing first.
- It is independent of fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108; see the engine-socket key question.
- feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117 depends on it.
- Proposed milestone: backlog (P1), picked by the release-start fill.
- Related:
- feat(cli): sandbox enforcement audit declared vs engine vs enforced (
devops sandbox audit) #698, the sandbox enforcement audit (a neighbour, not a parent; this item lands before feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117). It checks the runtime controls (capabilities, seccomp,no-new-privileges), not what is mounted. - feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117, whose rootless user mapping depends on this fix.
- feat(cli): sandbox enforcement audit declared vs engine vs enforced (
Update 2026-10-08: delivered scope
Delivered on fix/1115-sandbox-workspace-runtime-dirs, branched from release/v0.2.29 at 910b823. Where the delivered scope differs from the body above:
- Engine endpoint without the egress check. The body proposed calling
DockerEngineService.resolve_host. That runs the egress check, which looks up a tcp host's DNS when private networks are disallowed.devops sandbox deploy --dry-runvalidates the workspace, so that design would have added a request to a dry run. Instead,resolve_hostis split:configured_host()readsDOCKER_HOSTor the default socket, with no check, and the workspace check uses it.resolve_host()builds on it and keeps the egress check forclient().- So the body's statement that the tcp egress check "now runs before the workspace is accepted" no longer holds: a tcp endpoint names no socket and is not checked here.
- Which socket is followed. The check follows the socket that
DOCKER_HOSTnames, or the default/var/run/docker.sock. A socket chosen through a Docker context is followed once fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108 extendsconfigured_host(). - Socket path from docker-py's adapter, not
urlsplit.DockerEngineService.unix_socket_path()usesparse_hostand thenUnixHTTPAdapter(base_url).socket_path.urlsplit(...).pathdisagrees with docker-py on the legacyunix://tmp/engine/docker.sockform, which is among the tested cases. - Symlinked socket. When the socket file is itself a symlink, as Docker Desktop's WSL integration makes
/var/run/docker.sock, the check protects both the directory that holds the link and the directory the link leads to. A tested case covers this for both runners. - Unparseable endpoint. A
DOCKER_HOSTthat docker-py cannot parse refuses every workspace withSandboxValidationError.devops docker sandboxanddevops test sandboxre-raise it asDockerSandboxError. This covers both an unsupported scheme such asfd://and a malformed endpoint such astcp://host:abc, for all three commands and both MCP tools. - Refusal message. The new refusal names both the workspace and the protected directory.
/var/runis still refused first by the symlink rule, and/etc/sslby the system-directory rule. - Command name.
devops testin the body isdevops test sandbox. - Test changes. "Existing tests pass unchanged" did not hold:
- the two blocks that asserted the old
docker.socksubstring refusal now refuse the workspace that holds theDOCKER_HOSTsocket; - the two MCP tests that used the default workspace
.now passtmp_path, because a runner's checkout lies under/home, whichsandbox.exclude_home_dirrefuses; - a dry-run test shows
devops sandbox deploy --dry-runwith a tcp endpoint makes no host lookup.
- the two blocks that asserted the old
- Also removed. The duplicated
_FORBIDDEN_ROOTSsets, whichis_forbidden_system_pathalready covers. - Behaviour change.
devops docker sandboxanddevops test sandboxnow also refuse..workspaces and system subpaths such as/etc/ssl, asdevops sandbox deployalready did. The changelog says so. - Follow-ups. fix(cli): docker sandbox and test sandbox dry runs check the workspace as the real run does #1383: the two other dry runs still skip the workspace check. fix(security): a sandbox workspace never holds the user's ssh agent or X11 socket #1384: the SSH agent and X11 sockets.
- Person steps. Both "Pending a person" checks run after merge, and their results are recorded on this issue.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Moved to v0.2.29: v0.2.29 started with fewer than its 12 items and was topped up to 12 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)
fix(security): keep engine sockets and runtime directories out of san…
fix(security): keep engine sockets and runtime directories out of san…
dan-petty-bot commentedon Oct 8, 2026
What changed
#1385, merged into
release/v0.2.29as e3fff79.12 file(s) changed.
How it was verified
Check runs at 8ce4fce:
Acceptance Criteria of
docs/agent/tasks/task-1115-sandbox-workspace-never-exposes-engine-socket-or-runtime-dir.md:validate_sandbox_workspace.devops docker sandboxanddevops test sandboxstill raiseDockerSandboxError, anddevops sandbox deploystill raisesSandboxValidationError.test_a_workspace_overlapping_a_socket_directory_is_refused_before_any_engine_call(tests/test_sandbox_lifecycle.py), parametrised over both runners, refuses each case before any engine call, and the client mock records no call. The cases are/run,/run/user/1000,/run/user/1000/gnupgand/var/run;XDG_RUNTIME_DIRitself, a directory under it and the directory that holds it; theDOCKER_HOSTsocket directory, a directory under it and the directory that holds it, in both theunix:///absand theunix://relform; the directory a symlinkedDOCKER_HOSTsocket leads to;fd://andtcp://host:abc; and/etc/ssl.tmp_pathworkspace is mounted by both runners withDOCKER_HOSTunset and withDOCKER_HOST=tcp://192.0.2.1:2375./var/runis refused by the symlink rule and/etc/sslby the system-directory rule, and each of those messages names the workspace.workspace="/run/user/1000", or withDOCKER_HOSTset tofd://ortcp://host:abc, each tool raisesSandboxValidationErrorand_run_mcp_cmdis not called.rg -n 'docker\.sock' src/devops_cli/docker/sandbox.py src/devops_cli/sandbox/engine.pyprints nothing.CONST_FORBIDDEN_SYSTEM_DIRSkeeps its entries, andrun_subprocess(["pwd"], cwd=Path("/run"))still runs (tests/test_process.py).devops sandbox deploy --dry-runwithDOCKER_HOST=tcp://example.com:2375and private networks disallowed exits 0 without a host lookup.docker.socksubstring blocks (tests/test_sandbox_lifecycle.py,tests/test_security_sandbox_and_protection.py) now refuse the workspace that holds theDOCKER_HOSTsocket. The two MCP tests that used the default workspace.passworkspace=str(tmp_path), because a GitHub runner's checkout lies under/home. Every other sandbox and MCP test passes unchanged.changelog.d/1115.mdlists the workspaces that are now refused. The tests are offline, start no container, build no realDockerClientand each run well under 1 s.DOCKER_HOST, or the default, names; fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108 extendsconfigured_host()to Docker contexts, and the check follows it then.devops docker sandbox --workspace /run/user/$(id -u) -- true, thendevops docker sandbox --workspace "$XDG_RUNTIME_DIR" -- true, and the MCPdocker_sandboxtool withworkspaceset to/run/user/<uid>. Confirm that each is refused before any container is created, and record the results on the issue./run/user/$(id -u)and the commandpython3 -c 'import socket; socket.socket(socket.AF_UNIX).connect("/workspace/bus")'. Record on the issue whether the connect succeeds. It only connects and sends no bus message.feat(release): v0.2.29 (#1455)