dtshim
dtshim lets you invoke commands from a Docker container and execute them on the host.
The client inside the container forwards the invocation to the host daemon and
returns the output and exit code. To the calling program, it looks like running
a regular command.
For example, in autonomous agent development, an agent runs in an isolated
container where some commands cannot be executed: they may require access to
a corporate network, system capabilities, or tools available only on the host.
With dtshim, the agent can invoke these commands from its own environment.
A CLI for internal services can stay on the host, where access to those services is already configured. There is no need to install the tool or its dependencies in the container image.
How it works
The package consists of two programs:
dtshimd— the host daemon. Accepts requests through TCP or a Unix socket and starts processes.dtshim— the client inside the container. Sends the command name, arguments, environment variables, and standard input to the daemon, then returns the output and exit code.
Create a symbolic link to dtshim for each command you want to forward:
Calling git --version through this link runs git --version on the host.
Select the transport with --transport tcp|unix or the
DTSHIM_TRANSPORT=tcp|unix environment variable.
TCP is the default, and the daemon listens on 127.0.0.1:{20001-65535}.
At startup, the daemon writes the TCP address or Unix socket path to stdout.
In Unix mode, if both --socket and DTSHIM_SOCKET_PATH are omitted, the daemon
creates a socket in a temporary directory.
Server (dtshimd)
| Setting | Argument | Environment variable |
|---|---|---|
Transport (tcp or unix) |
--transport <tcp/unix> |
DTSHIM_TRANSPORT |
| Unix socket path | --socket <PATH> |
DTSHIM_SOCKET_PATH |
| Host/container path mappings | --volume_mapping <HOST:DOCKER> |
DTSHIM_VOLUME_MAPPING |
| Allowed commands policy | --policy <FILE> |
DTSHIM_POLICY |
| Connection token | --token <TOKEN> |
DTSHIM_TOKEN |
| Detailed logging | --debug |
— |
The daemon logs the command name, exit code or signal, and errors to stderr.
The --debug flag also logs command arguments and the contents of stdin, stdout, and stderr.
Volume mapping replaces paths in cwd, args, env, stdin, stdout, and stderr.
Client (dtshim)
The client also defaults to TCP. Configure it only through environment variables:
| Setting | Argument | Environment variable |
|---|---|---|
Transport (tcp or unix) |
— | DTSHIM_TRANSPORT |
TCP address (HOST:PORT) |
— | DTSHIM_TCP_ADDR |
| Unix socket path | — | DTSHIM_SOCKET_PATH |
| Connection token | — | DTSHIM_TOKEN |
The client requires the address or socket path to be passed through environment variables.
The token is optional: if set on the daemon, pass the same DTSHIM_TOKEN to the client.
Update the client and daemon together.
Daemon limits: 128 sessions, 10 seconds for the first complete request after accepting a connection.
DTSHIM_TRANSPORT=unix DTSHIM_SOCKET_PATH=/run/dtshim/socket
DTSHIM_TRANSPORT=tcp DTSHIM_TCP_ADDR=host.docker.internal:20001
Allowed commands and arguments
Without a policy, commands are unrestricted. With a policy, executable pins an absolute
host path regardless of the client's PATH. Omitted or null allow permits
arbitrary arguments for that command; a configured list requires a match with one of its rules.
In env.host: [HOME, {LANG: "C.UTF-8"}], a name preserves the daemon's value and a pair
sets a fixed value; the client cannot override either.
env.allow: null/omitted permits all client variables, [] none, a list only the named ones.
Names in env.host must belong to the configured env.allow list; daemon inheritance is unchanged.
value and positionals use full regex matches; required makes an option mandatory,
while repeat permits repetitions. Restart the daemon to apply policy changes.
Install with Cargo
Install the client in the container and the daemon on the host.
Usage example on Linux
In this example, Docker Engine and the daemon run on the same Linux host, which already has Git installed.
1. Install and start the daemon
Download the archive for your platform from Releases.
| Host platform | Archive |
|---|---|
| Linux x86_64 | dtshim-<version>-linux-x86_64.tar.gz |
| Linux ARM64 | dtshim-<version>-linux-arm64.tar.gz |
| macOS Apple Silicon | dtshim-<version>-macos-arm64.tar.gz |
<version> is the selected release tag, for example v0.7.0.
Each archive contains dtshim and dtshimd. To install the daemon on Linux x86_64:
VERSION=v0.7.0
2. Add the client to your Docker image
Create a Dockerfile:
FROM debian:bookworm-slim
COPY --from=ghcr.io/korableg/dtshim:latest /dtshim /usr/local/bin/dtshim
RUN mkdir -p /opt/host-bin \
&& ln -s /usr/local/bin/dtshim /opt/host-bin/git
ENV PATH="/opt/host-bin:${PATH}"
The ghcr.io/korableg/dtshim image contains only the statically linked Linux client
for linux/amd64 and linux/arm64.
3. Connect the container to the daemon
Mount the socket directory and specify the socket path inside the container:
The command prints the version of Git installed on the host. The container runs
with the daemon user's UID/GID so it can access the socket in the private directory.
DTSHIM_SOCKET_PATH is required by the client in Unix mode.
To connect over TCP on Linux, start the daemon without arguments:
Pass the address printed to stdout through the DTSHIM_TCP_ADDR environment variable.
This TCP example targets Docker Engine on Linux: host networking lets the
container connect to the daemon's 127.0.0.1 address.