Description
The current Dockerimage provided for the Sandbox SDK only contains bun, sandboxes with a wider rage of tools / libraries available could be highly valuable too.
I personally created a draft of a extended Dockerfile that also includes Python, including a couple of common python packages often used by ChatGPT, Antropic / Google's sandbox for running python, and added utilities to instantly invoke given code
This is useful for people needing quick solution for code execution within their LLMs apps, even better, would an additional MCP server and client that runs within the Dockerfile or within the container's durable object for instant utility.
Having a small set of presets for Dockerfiles could be useful for the Sandbox SDK.
Resources:
https://platform.openai.com/docs/assistants/tools/code-interpreter
https://ai.google.dev/gemini-api/docs/code-execution
https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool
Example Dockerfile:
FROM oven/bun:alpine AS builder
## Add build dependencies and Python
RUN apk add --no-cache \
python3 \
py3-pip \
build-base \
gcc \
g++ \
musl-dev \
linux-headers \
libffi-dev \
openssl-dev \
python3-dev \
jpeg-dev \
zlib-dev \
freetype-dev \
lcms2-dev \
openjpeg-dev \
tiff-dev \
harfbuzz-dev \
fribidi-dev \
proj-dev \
geos-dev \
gdal-dev
## Install uv and Python packages with balanced optimization for LLM sandbox
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN uv pip install --system --break-system-packages --no-cache --no-deps \
# Essential data science core
numpy pandas matplotlib scipy \
# File processing essentials
pillow openpyxl xlrd pyarrow \
# Document generation (important for LLM tasks)
fpdf pylatex reportlab PyPDF2 python-docx python-pptx \
# Web and markup processing
lxml jinja2 \
# Image processing
imageio \
# Utilities
python-dateutil pytz tqdm joblib \
# Math and validation
sympy jsonschema \
# Basic packages
attrs six packaging && \
# Install packages with dependencies (useful for LLM tasks)
uv pip install --system --break-system-packages --no-cache \
# ML and stats (users might request these)
scikit-learn seaborn \
# Specialized tools that LLM might use
contourpy \
# Lighter alternatives
tabulate pyparsing striprtf toolz && \
# Aggressive cleanup
find /usr -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \
find /usr -type f -name "*.pyc" -delete && \
find /usr -type f -name "*.pyo" -delete && \
find /usr -type d -name "*.dist-info" -exec rm -rf {} + 2>/dev/null || true && \
find /usr -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \
find /usr -type d -name "test" -exec rm -rf {} + 2>/dev/null || true && \
find /usr -name "*.so" -exec strip {} + 2>/dev/null || true
FROM oven/bun:alpine AS runtime
## Install minimal runtime dependencies using Alpine packages where possible
RUN apk add --no-cache \
python3 \
py3-pip \
# Use Alpine packages for common libraries (smaller)
py3-numpy \
py3-pillow \
# Runtime libs only
jpeg zlib freetype lcms2 openjpeg tiff \
harfbuzz fribidi proj geos gdal \
libffi openssl
## Copy only essential Python packages (skip Alpine-provided ones)
COPY --from=builder /usr/lib/python3.12/site-packages /usr/lib/python3.12/site-packages
COPY --from=builder /usr/bin/python* /usr/bin/
## Remove duplicates and unnecessary files in final stage
RUN find /usr -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \
find /usr -type f -name "*.pyc" -delete && \
rm -rf /usr/share/doc/* /usr/share/man/* /usr/share/info/* && \
rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
WORKDIR /app
## The image build context is the directory of the Dockerfile, so we need to copy the container_src from the sandbox node_modules
COPY ./node_modules/@cloudflare/sandbox/container_src .
EXPOSE 3000
CMD ["bun", "run", "index.ts"]