Console
← Journal / SECURITY

Zero-Trust Isolation for AI-Generated Web Sandboxes

How we isolate AI-generated React and Vite containers, strip platform secrets at the proxy boundary, and defend against sandbox-to-account pivot chains.

UNTRUSTED SANDBOX uid=1000:1000 --cap-drop=ALL no-new-privileges --pids-limit=128 /preview/<pid> ยท /s/<slug> ZERO COOKIE/CSRF CONTROL PLANE HttpOnly Session Guard Referer Firewall Dotfile 404 Block pub_<sha16> Gallery IDs domainfa.com/api/*
Table of Contents
Key Takeaways
  • →AI-generated frontends are untrusted third-party code: run every build in a rootless, capability-dropped container (--cap-drop=ALL, uid=1000:1000).
  • →Block /.env, /.session_id, and /node_modules/.bin at the proxy while allowing Vite's /node_modules/.vite/deps/ ESM cache so apps still hydrate.
  • →Treat /preview/ and /s/ Referers as hostile origins in CSRF middleware even when served from the same apex hostname.

Whenever an AI builder lets users generate arbitrary JavaScript, CSS, and server configurations in one prompt, the preview surface stops being harmless static HTML. From a security standpoint, every user-generated frontend is untrusted third-party code executing inside the user's browser.

After an internal security review across DomainFA's Go API and Dockerized builder infrastructure, we hardened three architectural boundaries between untrusted sandboxes and the control plane.

Rootless Capability-Dropped Builder Containers

Even if untrusted generated code or build scripts attempted local escape inside a sandbox container, kernel surface area is constrained at container launch:

BASH
docker run -d --name dfb-<project_id> \
  --user 1000:1000 \
  --cap-drop=ALL \
  --security-opt=no-new-privileges:true \
  --pids-limit=128 \
  --memory=1024m \
  --network builder-net \
  domainfa-template:latest

Separating ephemeral container runtime from durable source custody on a dedicated per-project data volume allows aggressive memory and process caps without losing built websites during container restarts.

Narrow Dotfile Filtering Without Breaking Vite ESM Hydration

Naively blocking all paths containing a dot segment (/.) stops sensitive .env and .git leaks, but it unintentionally breaks Vite's pre-bundled dependency chunks served under /node_modules/.vite/deps/*.js.

We narrowed the reverse-proxy gate explicitly:

Request Path PatternEdge DecisionRationale
/.env, /.git/*, /.session_id404 BlockedPrevents secret/session metadata leakage
/node_modules/.bin/*404 BlockedBlocks binary/CLI inspection
/.. traversal segments404 BlockedStops path-normalization escapes
/node_modules/.vite/deps/*200 AllowedRequired for React + Vite ESM client hydration

Sandbox Referer Firewall & Privacy Headers

Serving previews under domainfa.com/preview/<pid>/ or domainfa.com/s/<slug>/ requires guarding against same-site JavaScript attempting fetch('/api/...') with ambient cookies:

  • Control-plane Referer deny: DomainFA's csrfGuard rejects every non-GET request carrying a cookie whenever Referer matches /preview or /s/, returning 403 Forbidden before reaching any handler.
  • Unpublished sandbox de-indexing: Private previews emit X-Robots-Tag: noindex, nofollow, noarchive alongside strict Permissions-Policy: camera=(), microphone=(), geolocation=(), browsing-topics=().
  • Publisher anonymity on gallery feeds: Public gallery cards hash internal identifiers into pub_<16hex> tokens so internal account IDs never enumerate across /api/builder/gallery.

If your engineering team is hardening an AI coding agent, multi-tenant preview proxy, or SaaS control plane and wants a second pair of offensive eyes, reach our DomainFA Security Desk directly or email [email protected].

Direct Domain Search

Find an available domain across 900+ TLDs