: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 notebook sandbox image (Python notebooks).
FROM ubuntu:24.04
# Set environment variables to prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
# Install system packages (expanded for notebook environments)
RUN apt-get update && \
apt-get install -y \
# Core tools
curl \
wget \
git \
vim \
nano \
tree \
htop \
unzip \
zip \
jq \
# Build tools
build-essential \
pkg-config \
# Languages and runtimes
python3 \
python3-pip \
python3-venv \
python3-dev \
# Databases
sqlite3 \
postgresql-client \
mysql-client \
redis-tools \
# System libraries often needed by Python packages
libssl-dev \
libffi-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
# Other useful tools
ca-certificates \
gnupg \
sudo \
&& rm -rf /var/lib/apt/lists/*
# Install Node.js 26.x. NODEJS_VERSION works as in Dockerfile.sandbox-base (the reason is there).
ARG NODEJS_VERSION
RUN curl -fsSL https://deb.nodesource.com/setup_26.x | bash - && \
apt-get install -y "nodejs${NODEJS_VERSION:+=$NODEJS_VERSION}" && \
rm -rf /var/lib/apt/lists/*
# Install additional language package managers
RUN npm install -g yarn pnpm typescript ts-node nodemon
# Install GitHub CLI
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
apt-get update && \
apt-get install -y gh && \
rm -rf /var/lib/apt/lists/*
###
# Agent SDK
###
# Set up /scripts as a Node.js project and install @posthog/agent
RUN mkdir -p /scripts && \
cd /scripts && \
npm init -y && \
npm install @posthog/[email protected]
# Download agent runner script from GitHub
RUN cd /scripts && \
curl -fsSL https://raw.githubusercontent.com/PostHog/posthog/master/products/tasks/scripts/runAgent.mjs \
-o runAgent.mjs && \
chmod +x runAgent.mjs
# 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
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
# Install common notebook Python dependencies
RUN python3 -m venv /opt/notebook-venv && \
/opt/notebook-venv/bin/pip install --no-cache-dir --upgrade pip && \
/opt/notebook-venv/bin/pip install --no-cache-dir \
ipython \
jupyter \
jupyterlab \
notebook \
ipywidgets \
numpy \
pandas \
scipy \
scikit-learn \
matplotlib \
seaborn \
plotly \
pyarrow \
duckdb \
polars \
sqlalchemy \
requests \
lxml \
beautifulsoup4 && \
/opt/notebook-venv/bin/python -m ipykernel install --sys-prefix
ENV VIRTUAL_ENV=/opt/notebook-venv
ENV PATH="/opt/notebook-venv/bin:$PATH"
RUN python3 --version && \
node --version && \
npm --version
# Bake the notebooks SQLV2 kernel package. The backend launches it from here when
# the stamp matches the package hash it expects, and uploads the same modules as a
# tarball when it does not, so a kernel edit never waits on an image build.
# kernel_package.py supplies both the destination and the stamp, so this image and
# the backend cannot drift apart on where the package lives or how its hash is
# derived. This stays last because it invalidates on every kernel edit and the pip
# layer above is expensive to rebuild. The import check enforces the package's rule
# that it may only use libraries this image already carries.
COPY products/notebooks/backend/kernel_package.py /tmp/nb_kernel_build/kernel_package.py
COPY products/notebooks/backend/sandbox/kernel/ /tmp/nb_kernel_build/sandbox/kernel/
RUN ROOT="$(python3 /tmp/nb_kernel_build/kernel_package.py --baked-root)" && \
mkdir -p "$ROOT" && \
cp -R /tmp/nb_kernel_build/sandbox/kernel "$ROOT/nb_kernel" && \
python3 /tmp/nb_kernel_build/kernel_package.py > "$ROOT/VERSION" && \
rm -rf /tmp/nb_kernel_build && \
test -s "$ROOT/VERSION" && \
PYTHONPATH="$ROOT" python3 -c \
"import nb_kernel.server, nb_kernel.executor, nb_kernel.bootstrap, nb_kernel.result_store"
CMD ["/bin/bash"]