Sign inSign up

thanosprime/entities-api-sandbox

By thanosprime

•Updated 7 months ago

Image
0

3.7K

thanosprime/entities-api-sandbox repository overview

⁠Entities Sandbox v1 — Secure Code‑Execution Sidecar 🛡️🐳

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.


⁠🔑 Why a Separate Sandbox?

RiskSandbox Mitigation
Arbitrary exec() from LLM toolsFirejail seccomp, no root, no net by default
User‑supplied file uploadsRuns in per‑request temp dir, auto‑purged
GPU hog / runaway loopscgroups & --cpus / --memory limits
Secrets leakageContainer has zero cloud creds mounted

Result: API stays skinny & safe, sandbox can be blown away or scaled independently.


⁠Image Highlights

LayerNotes
python:3.11-slimBase image
firejailMandatory jail for every exec
pip install -r sandbox/requirements.txtnumpy, pandas, matplotlib (no seaborn), llama‑cpp tools
non‑root userUID 1001, HOME = /workspace
entrypoint.shStarts a tiny WebSocket bridge that the API calls

⁠Quick Start (stand‑alone demo)

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

⁠Environment Variables

VarDefaultPurpose
SANDBOX_MAX_EXEC_MS15000Hard wall for each code snippet (in ms)
SANDBOX_TMP_ROOT/tmpParent dir for per‑run temp dirs
SANDBOX_OPEN_PORTSnoneComma‑separated list if you really need egress

⁠Persistence / Files

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.


⁠GPU Support? 🔧

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.


⁠Typical Production Layout (docker‑compose)

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

⁠Updating

docker pull thanosprime/entities-sandbox:latest
docker compose up -d sandbox --force-recreate

⁠License

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.

Tag summary

Content type

Image

Digest

sha256:6029af25a…

Size

633 MB

Last updated

7 months ago

docker pull thanosprime/entities-api-sandbox