← ENGINEERING BLOG · ON-PREM DEVOPS · 7 MIN READ · DECEMBER 3, 2026

Docker Doesn't Hide Python Code: Stop docker cp Source Leaks On-Prem.

When you close your first $25,000 enterprise self-hosted deal and push your private FastAPI or Django image to the client's registry, remember one rule: a Docker image is just a tar archive. Any engineer with host access can run `docker export` and copy every `.py` file, prompt template, and pricing heuristic in three seconds.

Test your own Python repo in 50ms (Free): pip install -U pykevlar && pykevlar audit .
Browser Scanner →

1. Multi-Stage Dockerfile: Compile in Stage 1, Ship Zero Source in Stage 2

Use a two-stage Docker build where Stage 1 compiles your FastAPI/Django repo into a single ChaCha20 + Native C binary, and Stage 2 copies only that stripped ELF64 executable into a minimal debian:bookworm-slim runtime image with zero Python source files or pip caches:

FROM python:3.12-slim AS builder
RUN apt-get update && apt-get install -y --no-install-recommends gcc libc6-dev
WORKDIR /src
COPY . .
RUN pip install --no-cache-dir -r requirements.txt pykevlar
ARG PYKEVLAR_LICENSE
RUN PYKEVLAR_LICENSE="$PYKEVLAR_LICENSE" pykevlar build server.py \
    --protect app --mix-str --enable-bcc --anti-llm --outer -F -O /out

FROM debian:bookworm-slim
WORKDIR /srv
COPY --from=builder /out/server /srv/server
ENTRYPOINT ["/srv/server"]

Mount each enterprise tenant's 198-byte pyarmor.rkey via a Kubernetes Secret to enforce annual contract expiration 100% offline inside air-gapped VPCs.

Ship zero-.py distroless Docker images in GitHub Actions
PyKevlar Team unlocks unlimited Docker & CI builds ($59.25/yr Year 1 w/ LAUNCH25).
25% off Year 1 auto-applied (LAUNCH25) · 14-day compatibility money-back guarantee.
Try Monthly — $6.75 Mo 1 → Pro Annual ($29.25/yr) Team + CI ($59.25/yr)
$pip install -U pykevlar && pykevlar audit .
MORE FROM PYKEVLAR ENGINEERING
Shipping a Commercial AI Agent? How Competitors Extract Your System Prompts & RAG Logic From Python Binaries Read → How to Package a Commercial Streamlit or Gradio AI App Into a Single Protected Executable Read → How Attackers Dump Encrypted Python Code From RAM With Frida & PEP 669 (And How to Trap Them) Read →