The sandbox container is where untrusted code runs — never in the API pod.
Think: Jupyter‑grade Python interpreter, locked in a Firejail and chroot, wired for streaming I/O.
| Risk | Sandbox Mitigation |
|---|---|
Arbitrary exec() from LLM tools | Firejail seccomp, no root, no net by default |
| User‑supplied file uploads | Runs in per‑request temp dir, auto‑purged |
| GPU hog / runaway loops | cgroups & --cpus / --memory limits |
| Secrets leakage | Container has zero cloud creds mounted |
Result: API stays skinny & safe, sandbox can be blown away or scaled independently.
| Layer | Notes |
|---|---|
python:3.11-slim | Base image |
firejail | Mandatory jail for every exec |
pip install -r sandbox/requirements.txt | numpy, pandas, matplotlib (no seaborn), llama‑cpp tools |
non‑root user | UID 1001, HOME = /workspace |
entrypoint.sh | Starts a tiny WebSocket bridge that the API calls |
docker pull thanosprime/entities-sandbox:latest
docker run --rm -it \
--name entities-sandbox \
--cpus="2" --memory="4g" \
-p 9100:9100 \
thanosprime/entities-sandbox:latest
The sandbox exposes a WebSocket at ws://localhost:9100/exec
API containers in the same network hit it automatically; you can poke it with:
echo '{"code":"print(2+2)"}' | websocat ws://localhost:9100/exec
| Var | Default | Purpose |
|---|---|---|
SANDBOX_MAX_EXEC_MS | 15000 | Hard wall for each code snippet (in ms) |
SANDBOX_TMP_ROOT | /tmp | Parent dir for per‑run temp dirs |
SANDBOX_OPEN_PORTS | none | Comma‑separated list if you really need egress |
Mount a host dir if you want output files to survive:
-v $(pwd)/outputs:/workspace/outputs
Everything else lives in an ephemeral temp dir wiped after each run.
If you only need GPU inside the sandbox (e.g. whisper.cpp), start with:
--gpus all -e "SANDBOX_GPU=1"
Container includes CUDA 12 base libs but no heavy frameworks.
services:
api:
image: thanosprime/entities-api-api:latest
# … env & ports …
depends_on: [sandbox]
networks: [entities-net]
sandbox:
image: thanosprime/entities-sandbox:latest
networks: [entities-net]
deploy:
resources:
limits:
cpus: '2.00'
memory: 4G
docker pull thanosprime/entities-sandbox:latest
docker compose up -d sandbox --force-recreate
Same PolyForm Noncommercial 1.0.0 as the API container.
Let the code run wild — in a cage of your choosing.
Entities Sandbox makes sure the lions don’t eat the keeper.
Content type
Image
Digest
sha256:6029af25a…
Size
633 MB
Last updated
7 months ago
docker pull thanosprime/entities-api-sandbox