Skip to main content
Back to Community & Earn Hub
Q&A Questionsecurity +150 pt Bounty

gVisor (runsc) vs Firecracker for Multi-Tenant Untrusted Agent Sandboxes: How to fix 4x slower pip install & filesystem I/O syscalls?

@elena_rostova3 days ago 1533 views

We execute untrusted LLM-generated Python and Node scripts inside Kubernetes with gVisor (runtimeClassName: gvisor) because our cloud VMs don't allow nested KVM virtualization for Firecracker.

The Syscall I/O Bottleneck

Security isolation works great, but filesystem-heavy commands crawl:

  • pip install + pytest on a medium repo takes 9 seconds on native runc, vs 41 seconds inside gVisor!
  • Profiling shows thousands of openat / statx syscalls bouncing through gVisor's Gofer userspace filesystem proxy.

How can we speed up small-file I/O inside gVisor (directfs, tmpfs, overlay) without sacrificing kernel isolation?

1 Answers

Community Answers

@liam_oconnor Accepted Answer3 days ago

gVisor's legacy 9P Gofer IPC proxy adds ~15–25 microseconds per statx/openat syscall—which destroys performance on pip install, npm, and git status (which issue 50,000+ small-file syscalls!).

Without needing nested KVM or leaving GKE Sandbox, you can cut gVisor pip/pytest times by ~3.5x with three changes:


1. Enable gVisor directfs + Container-Local tmpfs / emptyDir Overlay

Modern gVisor (runsc) supports --directfs (lets the Sentry kernel talk directly to opened host FDs, bypassing Gofer 9P serialization!). Pair that with mounting emptyDir: { medium: Memory } (tmpfs) over /tmp, /root/.cache, and the working .venv:

yaml
apiVersion: v1
kind: Pod
spec:
  runtimeClassName: gvisor
  containers:
    - name: agent-sandbox
      image: my-agent-sandbox:latest
      volumeMounts:
        - name: fast-workspace
          mountPath: /workspace
        - name: fast-tmp
          mountPath: /tmp
  volumes:
    - name: fast-workspace
      emptyDir:
        medium: Memory # Pure in-RAM tmpfs inside Sentry -> zero host Gofer roundtrips!
        sizeLimit: 2Gi
    - name: fast-tmp
      emptyDir:
        medium: Memory
        sizeLimit: 1Gi

2. Pre-Bake Virtualenvs + Use uv Instead of pip

  1. Bake dependencies into the base image (COPY pyproject.toml ... && uv pip install --system) so agents don't unpack 8,000 wheel files at runtime.
  2. When an agent must install a package dynamically, use uv pip install (written in Rust, uses parallel hardlinks/clones and 10x fewer syscalls than pip).

Benchmark (GKE Sandbox gvisor):

  • Default Gofer + pip install: 41.2s
  • emptyDir: Memory + directfs + uv: 7.8s (5.2x faster with full gVisor kernel isolation!).

Have a solution or working configuration?

Sign in or create a free account to answer this question (+10 pts, +25 pts if accepted) and tag helpful AIStoreHub repositories.