1. Why Multi-Stage Dockerfiles & .pyc-Only Builds Don't Protect IP
A common misconception is that deleting .py files inside a Dockerfile and leaving only __pycache__/*.pyc protects a FastAPI container. On Python 3.12–3.14, neural decompilers like PyLingual and pycdc reconstruct .pyc files with near-100% fidelity—and worse, every string literal (system prompts, SQL queries, proprietary regexes, and internal endpoints) sits completely unencrypted inside co_consts, readable via plain strings.
2. Compiling FastAPI + Pydantic v2 + Uvicorn Into One Sealed ELF64 Binary
Unlike full-program C++ transpilers that struggle with Pydantic v2 Rust extensions (pydantic-core), dynamic FastAPI dependency injection, or torch C++ bindings, PyKevlar preserves 100% native CPython C-extension compatibility while sealing your first-party packages inside ChaCha20-Poly1305 function vaults and C machine code:
# Build directly on Linux CI—or cross-compile from Apple Silicon macOS with zero Docker:
pip install pykevlar
pykevlar register "PKA1-..."
pykevlar build app/main.py \
--name inference-gateway \
--target linux-x86_64 \
--protect app --protect agents --protect prompts --protect pricing \
--mix-str --enable-bcc --anti-llm --outer \
--collect-submodules uvicorn --collect-submodules fastapi \
-F -O dist-linux
# Verify zero plaintext .py modules or prompt strings exist in the output binary:
pykevlar verify dist-linux/inference-gateway --protect app,agents,prompts,pricing
3. Minimal Distroless Dockerfile (Zero .py, Zero pip, Zero Shell)
Once compiled, your customer-facing container copies only the single sealed ELF64 binary (and gets its hardware-bound pyarmor.rkey mounted at runtime):
FROM gcr.io/distroless/cc-debian12:nonroot WORKDIR /app COPY dist-linux/inference-gateway /app/inference-gateway EXPOSE 8000 ENTRYPOINT ["/app/inference-gateway", "--host", "0.0.0.0", "--port", "8000"]
4. What an Attacker Sees Inside the Container
strings /app/inference-gateway: System prompts and secret constants are encrypted by--mix-strinto masked C byte pools—zero prompt leakage.pyinstxtractor/binwalk: Fails immediately against theSPZ2stream-encrypted payload container.GhidraMCP/Frida/ PEP 669: Blocked at runtime by C-level anti-instrumentation checks and stripped symbol visibility (see our 7-Layer Threat Matrix and FastAPI & Django recipes).