Architecture Practices for Deploying AI Coding Sandboxes on the Public Internet

    This article walks through the architecture of running an AI coding sandbox on the public internet, covering image and version governance, three-layer isolation, a stateless gateway with session routing, authentication and multi-tenancy at the gateway, the cost model behind not self-hosting the control plane, mobile access boundaries, and a deployment checklist. The core takeaway: pin immutable versions, enforce execution/resource/network isolation, and collapse auth at the gateway to turn untrusted code execution into a reproducible, capped, auditable service.

    1. Background: Why Running a Sandbox on the Public Internet Is Not Simple

    Over the past year, AI coding tools and automated agent runtimes built around large language models (referred to collectively below as “AI coding sandboxes”) have rapidly become standard equipment for engineering teams. They need to do three things at once: execute arbitrary code, drive a browser for automation, and safely expose session state to remote users. Locally, these three things are a developer experience. On the public internet, they are an attack surface.

    One judgment from the original discussion is accurate: this is not a “raise shrimp” logic, nor is it a cloud-based worker per person. Managing it as a fleet of long-lived virtual machines causes cost, attack surface, and operational complexity to spiral out of control at the same time. The correct abstraction is: a short-lived, strongly isolated, quickly rebuildable execution environment, plus a stateless gateway layer.

    Official projects usually do not ship ready-to-use container images, and community images are mostly maintained by individuals. This has two direct consequences: versions are not traceable, and the supply chain is not trustworthy. So the first conclusion of this article is that public production environments must establish their own image governance baseline.

    2. Image and Version Governance: No Floating Tags

    The first rule of production is not to use floating tags. A floating tag means the same orchestration file pulls different content at different times, failures cannot be reproduced, and rollbacks are impossible.

    The recommended approach is to pin to an immutable version number or content digest, with all builds produced by an internal pipeline:

    1. # Pin the base image to an explicit version; avoid floating tags
    2. FROM runtime-base:2024.11-stable
    3. # Lock dependencies for reproducible builds
    4. COPY requirements.lock /tmp/requirements.lock
    5. RUN pip install --no-cache-dir -r /tmp/requirements.lock \
    6. && rm -rf /root/.cache
    7. # Run as a non-root user to reduce the payoff after an escape
    8. RUN useradd -m -u 10001 sandbox
    9. USER sandbox
    10. WORKDIR /workspace

    Three engineering constraints go with this:

    • Pull directly from the official registry, with no third-party acceleration or forwarding, to avoid content substitution;
    • Record build artifacts in a registry with provenance, capturing the base image digest, the dependency lock file hash, and the build time;
    • Rebuild on a schedule, so security updates to the base image reach production through rebuilding rather than in-place patching.

    3. Isolation Architecture: Three Layers of Boundaries

    Multi-user isolation cannot rely on “one directory per person.” Boundaries must be set at three layers simultaneously.

    The first layer is execution isolation. Each session maps to a separate container that mounts only the necessary working directory, runs without privileged mode, and restricts writable paths. The graphics and printing capabilities required for browser automation are provided through a minimal set of dependencies rather than by granting the container extra privileges.

    The second layer is resource isolation. CPU, memory, process count, and disk quota must be declared explicitly so a single session cannot drag down the node:

    1. # Illustrative resource boundaries for a single session
    2. limits:
    3. cpu: "2"
    4. memory: 4Gi
    5. pids: 512
    6. ephemeral-storage: 10Gi

    The third layer is network isolation. Outbound traffic is denied by default, with only model calls and required dependency sources allowed; inbound exposes only the gateway port, and the execution environment itself is never directly open to the public internet. Outbound traffic generated by browser automation should go through a unified egress proxy to make auditing and rate limiting easier.

    4. Access Layer Design: Stateless Gateway Plus Session Routing

    The gateway handles authentication, tenant identification, session routing, and rate limiting, and stays stateless itself so it can scale horizontally. The mapping between sessions and containers lives in shared storage; the gateway only reads it and does not hold it.

    1. Client → Access gateway (auth/rate limit) → Session scheduler → Execution container pool
    2. ↘ State store (session mapping/audit)

    Key design points:

    1. Session affinity is implemented through the mapping table rather than sticky sessions, so a gateway restart does not affect existing connections;
    2. Cold start optimization uses a pre-warmed container pool, with instances in the pool kept on standby so an arriving request only performs binding;
    3. Reclamation policy is based on two conditions, idle timeout and total cap: destroy on timeout to avoid zombie environments piling up.

    5. Authentication and Multi-Tenancy: Consolidate at the Gateway

    Authentication and multi-tenancy do not need to be pushed down into the execution environment; implementing them at the gateway is the most economical option. The core idea is to resolve the “identity-tenant-quota” triple at the entry point and pass only the tenant identifier downstream.

    • Identity authentication integrates with unified login and supports third-party authorization login to reduce registration friction;
    • Tenant quotas cover three dimensions: concurrent sessions, per-session duration, and total storage;
    • Audit logs record tenant, session, image version, and resource usage, and feed into a general logging service with monitoring and alerting to form a traceable chain.

    It is worth stressing that the isolation strength of multi-tenancy depends on the execution layer. Authentication only answers “who can get in” and cannot replace container and network boundaries.

    6. Cost Model: Why the Server Side Usually Does Not Open Source Self-Hosting

    A frequently misunderstood question is “why doesn’t the server side open source.” The reason is not technical difficulty but cost structure: the control plane needs continuous operations, images need continuous rebuilding, and public bandwidth and compute are billed by usage. Self-hosters take on very low marginal benefit while having to replicate the entire operational burden.

    The more pragmatic path is therefore: the service provider operates the control plane centrally and offers free or low-cost quotas, while the execution plane stays standardized and replaceable. If there is a genuine commercial need, differentiated quotas and billing can then be applied per tenant, which falls under normal commercial negotiation rather than architecture.

    7. Mobile Access: State Capability Boundaries Up Front

    The difficulty of mobile access is not the frontend but distribution and background survival. Mobile is better suited as an entry point for “remote observation and lightweight interaction”: viewing sessions, appending instructions, and receiving result notifications, while heavy work still runs in the server-side execution environment.

    If distribution channels are limited, it can degrade to a responsive web form, using progressive enhancement to provide push and offline caching. Explaining capability boundaries up front costs less than explaining experience differences after the fact.

    8. Deployment Checklist

    • Are images pinned to immutable versions and pulled directly from the official registry;
    • Do containers run as non-root, with privileged mode disabled and resource quotas declared explicitly;
    • Is outbound network denied by default and routed uniformly through an egress proxy;
    • Is the gateway stateless and session mapping externalized;
    • Are authentication and quotas consolidated at the entry point;
    • Do logs and monitoring cover the three dimensions of tenant, session, and image version;
    • Is one-click rebuild and fast rollback available.

    9. Conclusion

    Deploying an AI coding sandbox on the public internet is essentially about locking “untrusted code execution” into a box that is rebuildable, capped, and auditable, then wrapping it into a stable service with a stateless gateway. Version governance determines reproducibility, the three isolation layers determine the security floor, and gateway consolidation determines the operational ceiling. Get these three things solid, and the rest, mobile, multi-tenancy, and billing, are just increments.