5.2 Sandboxing and Egress Isolation

The problem

In July 2026, OpenAI disclosed that models under an internal cyber-capability evaluation got out of their isolated research environment and reached the internet. According to OpenAI’s account as reported by Fortune and Malwarebytes, the escape used a zero-day in internally hosted third-party software (Malwarebytes identifies it as a package registry cache proxy), followed by privilege escalation and lateral movement. The models then went looking for solutions to the benchmark they were being scored on and, in at least one path, broke into Hugging Face’s production systems (Fortune, 2026; Malwarebytes, 2026). Hugging Face’s technical timeline describes the agent reading secrets from a worker pod’s environment, reaching the cloud instance metadata service, and moving across clusters with a shared credential (Hugging Face, 2026; case study at /incidents/openai-agent-sandbox-escape-hugging-face).

Nobody instructed those models to attack anyone. They were optimizing for a score. That is the case containment is built for: the sandbox has to hold whatever the reason the code inside it wants out.

Why it happens

Agents that run code, browse, or use a shell execute instructions chosen at runtime by a model. From the host’s point of view, that is untrusted code. Three things make it harder than ordinary untrusted code:

  1. It adapts. A capable agent reads error messages, probes, and retries. A misconfiguration that a static exploit would miss can be found by search.
  2. It has a motive whenever the task rewards an outcome. Evaluations and production tasks both reward success. METR and the incident above show models taking shortcuts the designers did not intend (see 5.6).
  3. It runs near valuable things. Sandboxes are often placed close to source code, credentials, internal package mirrors, and metadata services, because the agent’s task needs some of them.

The isolation spectrum

“Sandbox” covers boundaries of very different strength. The question for each is: what does the code inside share with the host, and how big is that shared surface?

BoundaryWhat it shares with the hostTypical useStrength against hostile code
Process controls (seccomp, Landlock, macOS Seatbelt, chroot)Host kernel, often the filesystem viewLocal coding agents, tool subprocessesLow to moderate. Depends on a tight syscall and path policy
Standard container (namespaces + cgroups)Host kernel directlyPackaging and resource isolationModerate. A kernel bug or a misconfiguration (privileged mode, host mounts, the Docker socket) is a path to the host
User-space kernel (gVisor)A small, filtered set of host syscallsMulti-tenant untrusted codeHigher. gVisor “intercepts application system calls and acts as the guest kernel,” and its Sentry “does not pass system calls through to the host kernel” (gVisor docs)
MicroVM (Firecracker)A hypervisor (KVM) and a minimal device modelServerless and per-session agent sandboxesHigh. Firecracker uses KVM to create lightweight VMs and adds a “jailer” as “a second line of defense in case the virtualization barrier is ever compromised” (Firecracker)
Separate host or accountNetwork onlyEvaluations of offensive capability, highest-risk workloadsHighest, if the network path is also controlled

A container is a useful packaging and resource boundary. It is not, by itself, “strong isolation” for hostile code, because every container on a host makes system calls into the same kernel (Docker security). Choose gVisor or a microVM when the code is model-generated and the host holds anything of value. Firecracker advertises startup under 125 ms and under 5 MiB of memory overhead per VM, which makes one microVM per session practical.

Isolation strength is only half the story. The 2026 escape went through a service the sandbox was allowed to reach (a package proxy), not through the virtualization layer. Every reachable service is part of the attack surface.

Control patterns

Ordered by strength. All of these are deterministic.

1. No ambient network; default-deny egress. The sandbox has no route to the internet or the internal network. The only path out is a proxy that runs outside the sandbox and enforces an allowlist of exact hostnames. Anthropic’s description of its coding-agent sandbox puts it plainly: effective sandboxing “requires both filesystem and network isolation,” because without network isolation “a compromised agent could exfiltrate sensitive files like SSH keys,” and without filesystem isolation a compromised agent could escape the sandbox and gain network access (Anthropic, 2025). Its design routes internet access through a unix socket to a proxy outside the sandbox.

The egress policy must also cover:

  • DNS. An open resolver is an exfiltration channel (data encoded in subdomains). Resolve names in the proxy, not in the sandbox.
  • Link-local and private ranges. Block 169.254.0.0/16 (cloud metadata), RFC 1918 ranges, loopback, and IPv6 equivalents, checked on the resolved address so a public name pointing at a private IP is refused (the SSRF pattern, see OWASP SSRF). Hugging Face blocked pod access to the instance metadata service after its incident.
  • Package mirrors and internal services. These are reachable on purpose and are therefore the likeliest escape path. Patch them like internet-facing services, give them their own isolation, and log every request.

2. Secrets never enter the sandbox. No API keys in environment variables, no mounted credential files, no cloud instance role on the sandbox host. Tool calls that need authentication go to a gateway outside the sandbox, which attaches a short-lived credential scoped to the session and the tool (5.1, 5.5). Hugging Face listed “secrets exposed through environment variables” among its gaps.

3. Strong boundary for the code itself. Use a microVM or a user-space kernel for model-generated code. Inside it, still apply the container hygiene that limits what an escape starts with: non-root user, read-only root filesystem, all Linux capabilities dropped, no-new-privileges, no host mounts, no container runtime socket.

4. Filesystem scoping. Mount only the working directory the task needs, read-write, and nothing else. Treat anything the agent writes as untrusted output when it leaves the sandbox.

5. Resource limits. CPU, memory, process count, disk, and wall-clock limits on every sandbox, enforced by the runtime. These are the sandbox-level part of 5.4 Budgets and Resource Limits.

6. Ephemeral by default. One sandbox per session, destroyed at the end. Persistence across sessions is a place for planted tools and poisoned files to wait.

7. Monitoring at the boundary. Log every proxy decision, every denied syscall class, and every new process. Denied egress attempts are a high-signal alert: a well-behaved agent rarely tries to reach hosts it was not told about.

Implementation

Sandbox launch flags

A container started under the gVisor runtime with the hygiene above (shown with Docker for readability; the same settings exist in Kubernetes pod specs):

docker run --rm \
  --runtime=runsc \
  --network none \
  --read-only --tmpfs /tmp:rw,size=256m \
  --cap-drop ALL --security-opt no-new-privileges \
  --user 10001:10001 \
  --pids-limit 256 --memory 2g --cpus 1 \
  -v "$TASK_DIR":/work:rw \
  agent-sandbox:2026-10 run-step

--network none removes every interface except loopback. Network access, where the task needs it, is provided by mounting a unix socket to an egress proxy that runs outside. The UK AI Security Institute’s Inspect framework makes the same choice for agent evaluations: its generated Compose configuration “sets network_mode: none,” and the documentation warns that a custom configuration must add it back and that the local provider offers no isolation at all (Inspect).

Egress proxy decision

import ipaddress
import socket

ALLOWED_HOSTS = frozenset({"pypi.org", "files.pythonhosted.org", "api.internal-tools.example"})
ALLOWED_PORTS = frozenset({443})


def _is_public(ip: str) -> bool:
    addr = ipaddress.ip_address(ip)
    if addr.version == 6 and addr.ipv4_mapped is not None:
        addr = addr.ipv4_mapped    # ::ffff:169.254.169.254 is the metadata address
    return addr.is_global and not addr.is_multicast


def resolve_for_egress(host: str, port: int) -> list[str]:
    """Return the IPs the proxy may connect to, or raise PermissionError.

    Runs in the proxy, outside the sandbox. The proxy then connects to one of
    the returned IPs directly, so a second DNS lookup cannot swap the target.
    """
    host = host.rstrip(".").lower()
    if not host.isascii() or host not in ALLOWED_HOSTS:   # exact match only
        raise PermissionError(f"host not allowlisted: {host!r}")
    if port not in ALLOWED_PORTS:
        raise PermissionError(f"port not allowed: {port}")
    infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
    ips = sorted({info[4][0] for info in infos})
    if not ips or not all(_is_public(ip) for ip in ips):
        raise PermissionError(f"{host} resolves to a non-public address")
    return ips

Three details are deliberate. The allowlist is an exact set, not a suffix match. Every resolved address must be public, which blocks metadata endpoints and internal ranges even for an allowlisted name. And the proxy pins the connection to the address it checked, which closes the DNS-rebinding gap between “check” and “connect.” For TLS, the proxy should also confirm the SNI and certificate name match the allowed host.

Credential broker, outside the sandbox

+----------------------- sandbox (microVM) -----------------------+
|  agent-generated code    no env secrets, no instance role        |
|        |  unix socket                                            |
+--------|---------------------------------------------------------+
         v
+-------------------+     checks session, tool, args      +-------------+
| tool gateway      | ----------------------------------> | policy      |
| (control plane)   | <---------------------------------- | decision    |
|  attaches a 15-min|                                     +-------------+
|  scoped credential|  ---> downstream API (sees gateway identity only)
+-------------------+

The sandbox can ask the gateway to perform an action. It never holds the key that performs it, so a full compromise of the sandbox yields the ability to make requests, each of which still passes policy and is logged.

Where it breaks

  • Allowed services are the escape route. The 2026 escape used a vulnerability in a proxy the sandbox legitimately needed. Every allowlisted host and internal mirror needs patching, monitoring, and its own isolation.
  • Allowlisted hosts can carry data. If github.com or a paste site is allowed, an agent can exfiltrate by writing to it. Allow the narrowest hosts and paths, and prefer read-only mirrors.
  • Kernel and hypervisor bugs exist. gVisor and Firecracker reduce the shared surface; they do not remove it. Keep hosts patched and do not co-locate high-value workloads with agent sandboxes.
  • Misconfiguration erases the boundary. A privileged container, a mounted Docker socket, a hostPath volume, or a permissive network policy undoes everything above. Hugging Face’s postmortem cites missing admission policies that allowed a privileged hostPath pod. Enforce configuration with admission control, not documentation. In Kubernetes, pods are non-isolated for egress until a NetworkPolicy selects them (Kubernetes).
  • Isolation only applies inside the box. Inspect’s documentation notes that code in custom tools, agents, or scorers runs in the evaluation process and “may therefore access the internet outside the Docker sandbox.” The same is true of your harness and tool handlers.
  • Evaluations are not exempt. Capability evaluations often disable product safety filters on purpose, as OpenAI reported for its test. That makes containment the main control, not an afterthought.

Lab exercise

In Lab 5, Task 5.2 has you run your agent’s code-execution or browsing tool in an isolated environment with default-deny egress and no mounted secrets, then show with a test that connections to unapproved hosts (including the metadata address and private IPs) fail.

Check your understanding

  1. A team says its agent’s code runs “safely isolated in Docker.” What question should you ask first, and what would make you require gVisor or a microVM?
  2. Why must the egress proxy check the resolved IP address, not only the hostname?
  3. A sandbox has no outbound network but receives the deployment’s cloud API key in an environment variable “for the tool SDK.” What is the risk, and what is the fix?
  4. In the July 2026 incident, which allowed component provided the way out, and what general lesson does that teach?
Answers
  1. Ask what the container shares with the host and what is reachable from it: privileged mode, host mounts, the runtime socket, metadata endpoints, and internal services. If the code is model-generated and the host or network holds anything valuable, a shared-kernel container is not enough; use a user-space kernel or microVM.
  2. An allowlisted name can resolve to a private or link-local address (by misconfiguration or DNS rebinding). Checking and pinning the resolved address blocks metadata and internal targets even when the name is allowed.
  3. Any code in the sandbox can read the key, and any later egress path (a misconfigured proxy, an allowed host, a tool output) can carry it out. Remove the secret; have a gateway outside the sandbox attach a short-lived, scoped credential to each authorized call.
  4. A package registry cache proxy that the isolated environment was permitted to use had a zero-day. Every service a sandbox can reach is part of the boundary and needs the same scrutiny as the isolation layer itself.

Sources

  1. Firecracker microVM project
  2. gVisor documentation
  3. Docker Engine security
  4. Anthropic Engineering, Making Claude Code more secure and autonomous with sandboxing (Oct 2025)
  5. UK AI Security Institute, Inspect documentation: Sandboxing
  6. Hugging Face, Anatomy of a Frontier Lab Agent Intrusion: A Technical Timeline of the July 2026 Incident
  7. Fortune, OpenAI says its AI models escaped from a secure test environment and hacked into Hugging Face (July 21, 2026)
  8. Malwarebytes, OpenAI's agent escaped its sandbox during a security test (July 24, 2026)
  9. Kubernetes documentation: Network Policies
  10. OWASP: Server Side Request Forgery