Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

SandboxFix — Blast Radius Zero data agent

Vultr: Agent Rush Hackathon — Challenge 1 (Blast Radius Zero), Pattern A

Describe a data task in plain English, optionally upload a CSV. An LLM writes Python to do the job — but the code never runs on the server. It runs inside a disposable, network-less, resource-capped Docker sandbox that is destroyed the moment the run finishes. If the code fails, the traceback goes back to the LLM, which patches and retries (max 3 attempts), with every step visible in a full execution trace. You get the output files, the exact code that produced them, and a SHA-256 manifest so the results are verifiable.

Architecture

Browser ──► FastAPI app (Vultr VM, :80)
              │  POST /api/run
              ▼
            Agent loop ──► Vultr Serverless Inference (OpenAI-compatible API)
              │              writes / patches Python code
              ▼
            Docker sandbox (fresh container per attempt)
              python:3.12-slim + pandas + matplotlib
              workdir in ──► artifacts out ──► container destroyed
  • Backend: FastAPI + uvicorn on a Vultr VM (app/main.py, app/agent.py).
  • Model: Vultr Serverless Inference via a stdlib-only OpenAI-compatible client (app/llm.py) — no SDK dependency.
  • Sandbox lifecycle: fresh temp workdir per run → code + inputs copied in → docker run --rm → new files in the workdir collected as artifacts → workdir deleted (app/sandbox.py).

Containment design — the four focus areas

  1. Process isolation. Every attempt runs in its own container: --network none, --read-only rootfs (only the mounted workdir and a 64 MB tmpfs are writable), --cap-drop ALL, --security-opt no-new-privileges, running as user 65534 (nobody).
  2. Secret hygiene. VULTR_INFERENCE_API_KEY exists only in the web app's environment. It is never passed to docker run, never written to the workdir, and the sandbox has no network to exfiltrate anything with anyway. Generated code is also instructed to never read secrets.
  3. Resource limits. --memory 512m --memory-swap 512m (no swap escape), --cpus 1, --pids-limit 128 (fork-bomb brake), plus a hard wall-clock timeout enforced by the app: on expiry the container is killed, not just the client.
  4. Lifecycle destruction. Containers are --rm, workdirs are deleted after artifact collection, and artifacts leave the box only as byte copies served by the app. Nothing the code created persists in any environment.

Errors are data, not disasters: a nonzero exit or a timeout feeds the (truncated) traceback back to the model for a patch, up to 3 attempts, and the whole exchange is shown in the UI trace.

Local development (no Docker, no API key)

python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
# DevSandbox executes code with THIS interpreter, so it needs the data libs:
.venv/bin/pip install pandas matplotlib

LLM_STUB=1 SANDBOX_BACKEND=dev .venv/bin/uvicorn app.main:app --port 80
# open http://127.0.0.1:80

LLM_STUB=1 swaps the inference API for canned responses (a cleaning script, a simulated hostile script, an explanation) so the whole loop is testable offline. SANDBOX_BACKEND=dev swaps Docker for a host subprocess with a timeout and rlimits — for local testing only, it is not a security boundary.

Try it with the bundled sample:

curl -F task="Clean this CSV and save cleaned.csv" \
     -F file=@samples/messy.csv http://127.0.0.1:80/api/run

Production deploy (Vultr VM)

cp .env.example .env   # fill in VULTR_INFERENCE_API_KEY + VULTR_INFERENCE_MODEL
./deploy.sh            # installs Docker, builds the sandbox image, starts uvicorn on :80

deploy.sh in detail: installs Docker if missing → docker build -t sandboxfix-sandbox:latest sandbox/ → creates .venv and installs requirements → restarts uvicorn under nohup on port 80 → prints the health check (GET /healthz reports the active sandbox backend).

Demo script outline

  1. Normal task. Upload samples/messy.csv, preset “Clean this CSV”. Trace shows: plan → generated pandas code → sandbox run → cleaned.csv artifact with its SHA-256. Download it and re-hash it live to prove the manifest matches.
  2. Self-healing. Ask for a chart with a deliberately ambiguous column; the first attempt fails, the trace shows the traceback being fed back, and attempt 2 succeeds.
  3. The containment moment. Preset “Break the sandbox (demo)”: the model writes code that tries rm -rf /, reads environment secrets, opens a network connection, and loops forever. Watch each fail in turn — read-only fs / nothing to delete, no key in the environment, no network route — and the infinite loop get killed at the time cap. The host app stays up; the next normal task runs cleanly in a brand-new container. Blast radius: zero.

Layout

app/main.py       FastAPI app + artifact downloads
app/agent.py      plan → code → run → patch loop, trace, SHA-256 manifest
app/llm.py        stdlib OpenAI-compatible client (+ offline stub)
app/sandbox.py    DockerSandbox (prod) / DevSandbox (local tests only)
sandbox/Dockerfile  python:3.12-slim + pandas + matplotlib
static/index.html single-page UI (no external assets)
samples/messy.csv demo/test input
deploy.sh         one-shot Vultr VM deploy

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages