:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
# Dockerfile for the base sandbox image.
FROM golang:1.27.3 AS agent-shadow-builder
WORKDIR /src
COPY packages/agent/agent-shadow/ ./
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /agent-shadow .
# whisper.cpp and its model, for the transcribing-slack-audio skill. Audio from Slack voice
# messages is transcribed inside the sandbox and never leaves it. Ubuntu 24.04 ships no
# whisper.cpp package, so whisper-cli is built from a pinned, checksummed source release.
FROM ubuntu:24.04 AS whisper-builder
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential cmake curl ca-certificates && \
rm -rf /var/lib/apt/lists/*
ARG WHISPER_CPP_VERSION=1.9.5
ARG WHISPER_CPP_SHA256=ff1a9053feb509ff9d7729703355541ae9690073a6b1c40eb692c962e0dc1720
# GGML_NATIVE=OFF keeps the binary portable across sandbox hosts. On amd64 the AVX2 family is
# turned on explicitly, because a portable build without it transcribes about ten times slower.
RUN set -eux; \
curl -fsSL --retry 3 -o /tmp/whisper.tar.gz \
"https://github.com/ggml-org/whisper.cpp/archive/refs/tags/v${WHISPER_CPP_VERSION}.tar.gz"; \
echo "${WHISPER_CPP_SHA256} /tmp/whisper.tar.gz" | sha256sum -c -; \
mkdir /src; \
tar -xzf /tmp/whisper.tar.gz -C /src --strip-components=1; \
case "$(dpkg --print-architecture)" in \
amd64) cpu_flags="-DGGML_AVX=ON -DGGML_AVX2=ON -DGGML_FMA=ON -DGGML_F16C=ON -DGGML_BMI2=ON" ;; \
*) cpu_flags="" ;; \
esac; \
cmake -S /src -B /src/build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
-DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_SERVER=OFF -DGGML_NATIVE=OFF $cpu_flags; \
cmake --build /src/build -j"$(nproc)" --target whisper-cli; \
install -m 0755 /src/build/bin/whisper-cli /whisper-cli; \
/whisper-cli --help >/dev/null
# Multilingual small model, 5-bit quantized. It handles a 5 minute recording well inside the
# skill's processing limit on a 4 CPU sandbox. The revision pins the file, the hash verifies it.
ARG WHISPER_MODEL_REVISION=5359861c739e955e79d9a303bcbc70fb988958b1
ARG WHISPER_MODEL_FILE=ggml-small-q5_1.bin
ARG WHISPER_MODEL_SHA256=ae85e4a935d7a567bd102fe55afc16bb595bdb618e11b2fc7591bc08120411bb
RUN set -eux; \
curl -fsSL --retry 3 -o "/${WHISPER_MODEL_FILE}" \
"https://huggingface.co/ggerganov/whisper.cpp/resolve/${WHISPER_MODEL_REVISION}/${WHISPER_MODEL_FILE}"; \
echo "${WHISPER_MODEL_SHA256} /${WHISPER_MODEL_FILE}" | sha256sum -c -
# Trimmed ffmpeg and ffprobe for the transcribing-slack-audio skill. The Ubuntu ffmpeg package
# adds hundreds of MB of codec and media libraries. This build keeps only the demuxers and
# decoders for Slack voice messages and attachments (M4A, MP3, OGG/Opus, WAV, WebM) and the
# WAV output that whisper-cli reads.
FROM ubuntu:24.04 AS ffmpeg-builder
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential nasm xz-utils curl ca-certificates && \
rm -rf /var/lib/apt/lists/*
ARG FFMPEG_VERSION=7.1.1
ARG FFMPEG_SHA256=733984395e0dbbe5c046abda2dc49a5544e7e0e1e2366bba849222ae9e3a03b1
RUN set -eux; \
curl -fsSL --retry 3 -o /tmp/ffmpeg.tar.xz \
"https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz"; \
echo "${FFMPEG_SHA256} /tmp/ffmpeg.tar.xz" | sha256sum -c -; \
mkdir /src; \
tar -xf /tmp/ffmpeg.tar.xz -C /src --strip-components=1; \
cd /src; \
./configure \
--disable-everything --disable-autodetect --disable-doc --disable-debug --disable-network \
--disable-ffplay --enable-ffmpeg --enable-ffprobe --enable-small \
--enable-protocol=file,pipe \
--enable-demuxer=mov,mp3,ogg,wav,matroska,flac,aac \
--enable-parser=aac,aac_latm,mpegaudio,opus,vorbis,flac \
--enable-decoder=aac,aac_latm,mp3,mp3float,opus,vorbis,flac,pcm_s16le,pcm_s16be,pcm_s24le,pcm_s32le,pcm_f32le,pcm_u8 \
--enable-encoder=pcm_s16le --enable-muxer=wav \
--enable-filter=aresample,aformat,anull; \
make -j"$(nproc)"; \
install -m 0755 -s ffmpeg /ffmpeg; \
install -m 0755 -s ffprobe /ffprobe; \
/ffmpeg -version >/dev/null; \
/ffprobe -version >/dev/null
FROM ubuntu:24.04
# Set environment variables to prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
# Remove gh CLI telemetry
ENV GH_TELEMETRY=false
# Install system packages (expanded for coding environments)
RUN apt-get update && \
apt-get install -y --no-install-recommends \
# Core tools
curl \
wget \
git \
vim \
nano \
tree \
htop \
unzip \
zip \
jq \
# Build tools
build-essential \
pkg-config \
# Loader for the musl-linked @openai/codex binary bundled with @posthog/agent
musl \
# Languages and runtimes
python3 \
python3-pip \
python3-venv \
python3-dev \
# Databases
sqlite3 \
postgresql-client \
mysql-client \
redis-tools \
# OpenMP runtime for whisper-cli (transcribing-slack-audio skill)
libgomp1 \
# System libraries often needed by Python packages
libssl-dev \
libcurl4-gnutls-dev \
libexpat1-dev \
libffi-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
zlib1g-dev \
# Other useful tools
ca-certificates \
gnupg \
sudo \
&& rm -rf /var/lib/apt/lists/*
ARG GIT_VERSION=2.49.1
ARG GIT_SHA256=310831de967f1c8c5e8ff55f92807dea89f83dc3d3d2a5d16c209bd01a31def1
RUN set -eux; \
curl -fsSL -o /tmp/git.tar.xz \
"https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.xz"; \
echo "${GIT_SHA256} /tmp/git.tar.xz" | sha256sum -c -; \
mkdir /tmp/git; \
tar -xf /tmp/git.tar.xz -C /tmp/git --strip-components=1; \
make -C /tmp/git prefix=/usr NO_GETTEXT=YesPlease NO_TCLTK=YesPlease -j"$(nproc)" all; \
make -C /tmp/git prefix=/usr NO_GETTEXT=YesPlease NO_TCLTK=YesPlease install; \
rm -rf /tmp/git /tmp/git.tar.xz; \
git --version; \
git help -a | grep -q '[[:space:]]backfill'
# Install Node.js 26.x. The layer cache keys on this RUN text, so cd-sandbox-base-image.yml
# passes the newest nodesource package as NODEJS_VERSION to rebuild the layer when Node ships
# a release. A build without the arg installs the newest package.
ARG NODEJS_VERSION
RUN curl -fsSL https://deb.nodesource.com/setup_26.x | bash - && \
apt-get install -y --no-install-recommends "nodejs${NODEJS_VERSION:+=$NODEJS_VERSION}" && \
rm -rf /var/lib/apt/lists/*
# Install additional language package managers
ARG PNPM_VERSION=10.34.5
RUN npm install -g yarn "pnpm@${PNPM_VERSION}" typescript ts-node nodemon
# Install ruff and ty
# uv comes from its pinned, registry-verified official image (same pattern as the
# main Dockerfile) rather than piping a remote installer script to a shell.
COPY --from=ghcr.io/astral-sh/uv:0.13.4 /uv /uvx /usr/local/bin/
ARG RUFF_VERSION=0.14.11
ARG TY_VERSION=0.0.29
RUN UV_TOOL_BIN_DIR=/usr/local/bin uv tool install "ruff==${RUFF_VERSION}" && \
UV_TOOL_BIN_DIR=/usr/local/bin uv tool install "ty==${TY_VERSION}" && \
ruff --version && \
ty --version
# Install GitHub CLI without adding another apt repository refresh.
ARG GH_CLI_VERSION=2.97.0
RUN set -eux; \
arch="$(dpkg --print-architecture)"; \
curl -fsSL -o /tmp/gh.deb \
"https://github.com/cli/cli/releases/download/v${GH_CLI_VERSION}/gh_${GH_CLI_VERSION}_linux_${arch}.deb" && \
dpkg -i /tmp/gh.deb && \
rm /tmp/gh.deb
# Install agentsh for runtime egress policy enforcement
ARG AGENTSH_TAG=v0.18.3
RUN set -eux; \
version="${AGENTSH_TAG#v}"; \
arch="$(dpkg --print-architecture)"; \
case "$arch" in \
amd64) agentsh_sha256="4ac486eea1e10600c29078a7a992d2067774edfb66be1318a2acf1fcf8b6d774" ;; \
arm64) agentsh_sha256="d1393a27943d207442ea077b1d36d9561a8af5613e7b67d9f7d4fafd00626c6b" ;; \
*) echo "Unsupported architecture for agentsh: $arch" >&2; exit 1 ;; \
esac; \
curl -fsSL -o /tmp/agentsh.deb \
"https://github.com/canyonroad/agentsh/releases/download/${AGENTSH_TAG}/agentsh_${version}_linux_${arch}.deb" && \
echo "${agentsh_sha256} /tmp/agentsh.deb" | sha256sum -c - && \
dpkg -i /tmp/agentsh.deb && \
rm /tmp/agentsh.deb && \
agentsh --version && \
mkdir -p /var/lib/agentsh/sessions /var/lib/agentsh/quarantine /var/log/agentsh && \
chmod 777 /var/lib/agentsh /var/lib/agentsh/sessions /var/lib/agentsh/quarantine /var/log/agentsh
ENV AGENTSH_SERVER=http://127.0.0.1:18080
COPY --from=whisper-builder /whisper-cli /usr/local/bin/whisper-cli
COPY --from=ffmpeg-builder /ffmpeg /ffprobe /usr/local/bin/
COPY --from=whisper-builder /ggml-small-q5_1.bin /opt/whisper/models/ggml-small-q5_1.bin
ENV WHISPER_MODEL_PATH=/opt/whisper/models/ggml-small-q5_1.bin
RUN whisper-cli --help >/dev/null && ffmpeg -version >/dev/null && ffprobe -version >/dev/null
# Install rtk (https://github.com/rtk-ai/rtk), a proxy that compresses the output of
# common dev commands before it reaches the model. Claude runs auto-detect it on PATH
# and route eligible Bash commands through it via a PreToolUse rewrite hook; Codex has
# no command-rewrite channel, so its runs are told to prefix eligible commands in the
# developer instructions instead. POSTHOG_RTK=0 (set per run from the task processing
# context) opts a run out of both.
ARG RTK_VERSION=0.43.0
RUN set -eux; \
arch="$(dpkg --print-architecture)"; \
case "$arch" in \
amd64) rtk_asset="rtk-x86_64-unknown-linux-musl.tar.gz"; \
rtk_sha256="ff8a1e7766496e175291a85aeca1dc97c9ff6df33e51e5893d1fbc78fea2a609" ;; \
arm64) rtk_asset="rtk-aarch64-unknown-linux-gnu.tar.gz"; \
rtk_sha256="5519f7ca12e5c143a609f0d28a0a77b97413a8dce31c2681f1a41c24519a8731" ;; \
*) echo "Unsupported architecture for rtk: $arch" >&2; exit 1 ;; \
esac; \
curl -fsSL -o /tmp/rtk.tar.gz \
"https://github.com/rtk-ai/rtk/releases/download/v${RTK_VERSION}/${rtk_asset}" && \
echo "${rtk_sha256} /tmp/rtk.tar.gz" | sha256sum -c - && \
tar -xzf /tmp/rtk.tar.gz -C /usr/local/bin rtk && \
rm /tmp/rtk.tar.gz && \
rtk --version
###
# Agent SDK
###
# Set up /scripts as a Node.js project and install @posthog/agent.
# AGENT_VERSION is pinned, not "latest": the CD workflow used to resolve the
# npm "latest" dist-tag at build time, so any @posthog/agent release reached
# every sandbox image with no PostHog commit or review. Bump this deliberately
# in a reviewed PR when picking up a new agent release. COMMIT_HASH invalidates
# the layer for PostHog-side image changes that keep the agent version unchanged.
ARG AGENT_VERSION=2.4.315
ARG AGENT_TARBALL_SHA256="a494ebeed6a673436da54dfc26edb960b8da5194769bfe57e34e7c31df9f8876"
ARG AGENT_TARBALL_URL=https://github.com/PostHog/posthog/releases/download/agent-v${AGENT_VERSION}/posthog-agent-${AGENT_VERSION}.tgz
ARG COMMIT_HASH
RUN mkdir -p /scripts && \
cd /scripts && \
npm init -y && \
if [ -n "${AGENT_TARBALL_SHA256}" ] && curl -fsSL --retry 3 --retry-all-errors -o /tmp/posthog-agent.tgz "${AGENT_TARBALL_URL}"; then \
echo "${AGENT_TARBALL_SHA256} /tmp/posthog-agent.tgz" | sha256sum -c - && \
CACHE_BUST=${COMMIT_HASH} npm install /tmp/posthog-agent.tgz && \
rm /tmp/posthog-agent.tgz; \
else \
CACHE_BUST=${COMMIT_HASH} npm install "@posthog/agent@${AGENT_VERSION}"; \
fi && \
npm pkg set "dependencies.@posthog/agent=${AGENT_VERSION}"
# Install pre-built skills (PostHog + context-mill) into the plugin directory.
# The dist/skills/ directory is populated by the CD workflow's build_skills job.
COPY products/posthog_ai/dist/skills/ /tmp/skills/
COPY products/tasks/backend/sandbox/images/install-skills.sh /tmp/install-skills.sh
RUN chmod +x /tmp/install-skills.sh && \
/tmp/install-skills.sh /tmp/skills && \
rm -rf /tmp/install-skills.sh /tmp/skills
# Default git identity for bot-authored commits.
# Runs configured for user-authored pull requests receive
# GIT_AUTHOR_*/GIT_COMMITTER_* env vars that override these defaults.
RUN git config --global user.email "[email protected]" && \
git config --global user.name "PostHog Desktop"
# Block `git commit`/`git push` so unsigned commits cannot leave the sandbox
COPY products/tasks/backend/sandbox/images/git-guard.sh /opt/posthog/bin/git
RUN chmod +x /opt/posthog/bin/git
# Inject the per-actor GitHub token into every `gh` call (BASH_ENV only reaches
# non-interactive `bash -c`; the agent's interactive shell needs this shim).
COPY products/tasks/backend/sandbox/images/gh-guard.sh /opt/posthog/bin/gh
RUN chmod +x /opt/posthog/bin/gh
COPY products/tasks/backend/sandbox/images/hogli-shim.sh /opt/posthog/bin/hogli
RUN chmod +x /opt/posthog/bin/hogli
COPY products/tasks/backend/sandbox/images/cpu_billing_sampler.py /usr/local/bin/posthog-cpu-billing-sampler
RUN chmod +x /usr/local/bin/posthog-cpu-billing-sampler
COPY products/tasks/backend/sandbox/images/memory_watchdog.py /usr/local/bin/posthog-memory-watchdog
RUN chmod +x /usr/local/bin/posthog-memory-watchdog
COPY --from=agent-shadow-builder /agent-shadow /usr/local/bin/agent-shadow
ENV PATH="/opt/posthog/bin:${PATH}"
# This is required for the Claude Code SDK to allow --dangerously-skip-permissions as the root user
ENV IS_SANDBOX=1
ENV PYTHONPATH="/tmp/workspace"
WORKDIR /tmp/workspace
RUN python3 --version && \
node --version && \
npm --version && \
installed="$(node -p "require('/scripts/node_modules/@posthog/agent/package.json').version")" && \
if [ "$installed" != "${AGENT_VERSION}" ]; then \
echo "installed @posthog/agent $installed, expected ${AGENT_VERSION}" >&2; exit 1; \
fi && \
/scripts/node_modules/.bin/agent-server --help >/dev/null
COPY products/tasks/backend/sandbox/images/task_filesystem.py /opt/posthog/task-filesystem.py
RUN /usr/bin/python3 -I /opt/posthog/task-filesystem.py seed-home
CMD ["/bin/bash"]