Enterprise agent platform for building, deploying, and operating AI teammates.
# syntax=docker/dockerfile:1.6
ARG UV_VERSION=0.11.10
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
############################
# Locked sandbox requirements
############################
FROM python:3.11-slim AS sandbox-requirements
ENV UV_PYTHON_DOWNLOADS=0
COPY --from=uv /uv /uvx /usr/local/bin/
WORKDIR /build
COPY pyproject.toml uv.lock ./
# Export only the dedicated sandbox dependency group. The lock metadata stays
# in this build stage instead of becoming part of the runtime image.
RUN uv export --quiet --locked --only-group sandbox --no-emit-project \
--output-file /sandbox-requirements.txt
############################
# Sandbox runtime
############################
FROM node:22-slim AS sandbox
LABEL maintainer="xagent"
LABEL description="Full sandbox image with all tools"
COPY --from=uv /uv /uvx /usr/local/bin/
# Fixed npm/npx cache location, set before anything in this stage might
# invoke npx -- npm's default path is keyed to $HOME, which varies by
# exec user. The execution-scoped Chrome controller also passes this path
# explicitly to every sandbox child.
ENV NPM_CONFIG_CACHE=/opt/npm-cache
RUN mkdir -p "$NPM_CONFIG_CACHE" && chmod 0755 "$NPM_CONFIG_CACHE"
######################## python 3.11 install (apt)
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
netbase \
tzdata \
openssh-client \
python3.11 \
python3-pip \
python3-venv \
&& ln -sf /usr/bin/python3.11 /usr/local/bin/python \
&& ln -sf /usr/bin/python3.11 /usr/local/bin/python3 \
&& ln -sf /usr/bin/pip3 /usr/local/bin/pip \
&& rm -rf /var/lib/apt/lists/* \
&& python --version && pip --version
######################## browser install (apt): Chrome on amd64, Chromium on arm64
#
# Browser for the built-in "chrome" MCP connector (chrome-devtools-mcp).
# Dockerfile.backend's own INSTALL_CHROME block only covers the non-
# sandboxed path; should_sandbox_mcp_connection() routes every npx/uvx
# connector into *this* image once a sandbox is configured, so it needs
# the same browser or the connector fails with "Could not find Google
# Chrome executable". --build-arg INSTALL_CHROME=false skips it (and the
# npx cache below) for deployments that never enable the connector.
#
# The connector's launch_config currently passes
# --no-sandbox/--disable-setuid-sandbox even though Docker executes it as the
# uid 1100 sandbox user. Keep the connector hidden pending
# the security review tracked by the corresponding backend-image comment.
ARG INSTALL_CHROME=true
# Resolves "stable" to exactly /opt/google/chrome/chrome on Linux -- see
# Dockerfile.backend's block for the per-architecture rationale (no
# arm64 Chrome from Google; Chromium is CDP-compatible and gets
# symlinked to the same path so both images share one resolver path).
#
# fonts-liberation + fonts-noto-cjk: neither Debian's chromium package
# (fonts-liberation is only a Recommends, skipped by
# --no-install-recommends) nor node:22-slim ships any font, and headless
# Chrome/Chromium with none installed silently renders blank/tofu text
# instead of failing the build. fonts-noto-cjk matches what
# Dockerfile.backend's base stage already installs for this connector.
RUN if [ "$INSTALL_CHROME" != "true" ]; then \
echo "INSTALL_CHROME=$INSTALL_CHROME -- skipping Chrome/Chromium install"; \
else \
if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
apt-get update \
&& apt-get install -y --no-install-recommends -o Acquire::Retries=5 curl gnupg \
&& curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/google-chrome.gpg \
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] https://dl.google.com/linux/chrome/deb/ stable main" \
> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends -o Acquire::Retries=5 \
google-chrome-stable fonts-liberation fonts-noto-cjk \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false curl gnupg \
&& rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/google-chrome.list /usr/share/keyrings/google-chrome.gpg; \
elif [ "$(dpkg --print-architecture)" = "arm64" ]; then \
apt-get update \
&& apt-get install -y --no-install-recommends -o Acquire::Retries=5 \
chromium fonts-liberation fonts-noto-cjk \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /opt/google/chrome \
&& ln -s /usr/bin/chromium /opt/google/chrome/chrome; \
else \
echo "ERROR: unsupported architecture $(dpkg --print-architecture) for the chrome connector -- add an install branch, or build with --build-arg INSTALL_CHROME=false" >&2; \
exit 1; \
fi; \
[ -e /opt/google/chrome/chrome ] || { echo "ERROR: the Chrome/Chromium install did not produce /opt/google/chrome/chrome -- update the chrome-devtools-mcp resolver path handling" >&2; exit 1; }; \
fi
# Warm the npx cache for the version pinned in builtin_mcp_registry.py's
# launch_config, mirroring Dockerfile.backend's identical step, to skip
# the npm registry on launch. The execution-scoped Chrome controller passes
# this cache path explicitly. Both sandbox backends execute as the non-root
# `sandbox` user, so ownership is transferred before the offline smoke check.
#
# `--help` exercises resolution without starting Chrome, so this needs
# no display/GPU setup at build time. umask 0022, not 0000: only
# cross-user *read* access is needed during this root-owned build step. The
# completed tree is handed to the dedicated sandbox uid below so either
# backend can update npm metadata on a cache miss without world-writable files.
RUN if [ "$INSTALL_CHROME" = "true" ]; then \
umask 0022 && npx -y --prefer-offline [email protected] --help > /dev/null; \
fi
######################## tools dependencies
COPY --from=sandbox-requirements /sandbox-requirements.txt /tmp/sandbox-requirements.txt
# Install the exact versions exported from uv.lock. The import check fails the
# build if a supported runtime package is missing from the resulting image.
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system --break-system-packages \
-r /tmp/sandbox-requirements.txt \
&& rm /tmp/sandbox-requirements.txt \
&& uvx --version \
&& python -c "import cloudpickle, docx, fsspec, matplotlib, mcp; import numpy, openpyxl, pandas, pydantic, pydantic_settings"
# Allow pip install without --break-system-packages globally. Sandboxed tools
# can install their explicitly declared runtime dependencies as an unprivileged
# user after the container starts.
RUN printf '[global]\nbreak-system-packages = true\n' > /etc/pip.conf
########################
# Create sandbox user
RUN groupadd --gid 1010 sandbox \
&& useradd --uid 1100 --gid sandbox --shell /bin/bash --create-home sandbox \
&& chown -R 1100:1010 "$NPM_CONFIG_CACHE"
USER sandbox
WORKDIR /home/sandbox
# Prove the warmed package is usable by the sandbox runtime uid without network
# access. This also catches root-owned cache metadata before the image ships.
RUN if [ "$INSTALL_CHROME" = "true" ]; then \
CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS=1 NPM_CONFIG_OFFLINE=true \
npx -y --offline [email protected] --help > /dev/null; \
fi
CMD ["bash"]