Security model

7 min read

This page summarizes the security boundaries documented in teploy-sandbox v0.1.0 and teploy sandbox. It describes what the engine enforces today and where its limits are.

Hard invariants

teploy-sandbox is designed around three rules that must never be broken:

  • Never bind the control API publicly. The daemon speaks plain HTTP and listens on 127.0.0.1:7439 by default.
  • Never join runs to the teploy app network. Even on the open network tier, sandboxes are never attached to the teploy Docker network.
  • Never mount the Docker socket into a run.

Control plane and transport

  • Loopback + SSH tunneling: teploy sandbox host binds teploy-sandbox to 127.0.0.1:7439. Every CLI command connects over SSH TCP forwarding, reads the server's bearer token over SSH, and never sends the token outside the SSH connection. --addr rejects non-loopback addresses unless --allow-remote-addr is explicitly passed.
  • Bearer token on every route except /health: missing or invalid tokens receive 401.
  • Root-equivalent daemon: the systemd service runs as root because it drives Docker, and the unit carries no systemd sandboxing — loopback-only listening is the boundary.
  • Secrets on disk and in execs: --state-dir is 0700 and the stopped-run registry is 0600 (it stores stopped runs' environment variables). Per-exec env values reach Docker through a temporary 0600 --env-file removed after the call — never via command-line arguments or the docker CLI's own environment.
  • Verified binary delivery: teploy sandbox host checks the downloaded v0.1.0 binary against the SHA-256 pinned in the CLI and the release's checksums.txt before uploading. Upstream releases build in a read-only GitHub Actions job and publish from a separate job with every action pinned to a commit SHA.

Network egress tiers

Every run selects one of three egress tiers on create:

Tier Docker driver Experimental VM driver
none (default) Loopback only; no external network interface. No network device attached to the VM at all.
allowlist Internal teploy-sbx-egress-v2 bridge with inter-container communication and IPv6 disabled. Dedicated TEPLOY-SBX iptables INPUT chain admits only active proxy listeners; creation fails closed if the firewall cannot be enforced. Isolated network namespace with no link to the host and only the run's own proxy listening inside it.
open Docker's default NAT bridge with no proxy or filter. Reaches everything the host can route — including LAN, tailnet, cloud metadata, and other Docker networks (still never the teploy network). Intended for code you already trust. Public internet only by default: drops RFC1918, shared (100.64/10), link-local (169.254/16), loopback, multicast, and reserved ranges, blocks TCP port 25, disables IPv6, and never reaches the host or other guests. --vm-open-private re-enables private/shared/doc/benchmark ranges while keeping link-local, loopback, host, peer guests, and port 25 closed.

How allowlist works (and what it cannot do)

  • Runs reach the proxy via HTTP_PROXY / HTTPS_PROXY. The default allowlist covers major package registries and Git hosts (where a registry separates download and upload hosts, only the download host is listed; storage.googleapis.com, registry.k8s.io, and aka.ms are deliberately excluded by default).
  • Per-run egressAllow starts a private proxy with a random credential in its URL for that run only (both HTTP and CONNECT require the credential).
  • Only proxy-aware tools can reach the internet; raw sockets fail with a network error. SSH git remotes (port 22) and git:// (port 9418) cannot work over the HTTP proxy. Only ports 80 and 443 are allowed unless an entry names a port explicitly (host:port).

Container isolation (Docker driver)

  • Run user: executes as the non-root ship account (--sandbox-user) when present in the image, otherwise root (user: "root" forces root). Ship images configure uid 1000 with passwordless sudo.
  • Capabilities: root runs keep no-new-privileges and drop NET_RAW, MKNOD, and AUDIT_WRITE. Non-root runs drop no-new-privileges (so sudo works) and keep AUDIT_WRITE, with an otherwise identical capability bounding set ceiling.
  • Filesystem confinement: PUT/GET /v1/runs/{id}/files/{path} and teploy sandbox cp are confined to /work; path traversal returns 400.
  • Resource bounds: default 1 CPU, 1024 MiB RAM, 256 pids, 30-minute TTL (24h max). Optional gVisor runtime via SBX_RUNTIME=runsc.

Hypervisor confinement (experimental VM driver)

Under --driver vm (not installed by teploy sandbox host), each run gets its own Linux kernel under Cloud Hypervisor on KVM, and the hypervisor process is confined as if the guest had already compromised it:

  • Minimal jail: a helper enters fresh mount, PID, network, IPC, UTS, and cgroup namespaces, mounts a read-only tmpfs root with only the paths the hypervisor needs (the hypervisor binary, guest kernel at /kernel, VM disk node, /dev/kvm, /dev/urandom, and the VM's socket directory), runs pivot_root, detaches the old root, closes all extra file descriptors, and drops to the VM's UID. No /proc, /sys, /etc, or host Unix sockets exist in the jail; only a per-VM 64 KiB / 16-inode tmpfs socket directory is writable.
  • Dedicated UID and no KSM: each VM runs under its own UID/GID from a reserved 4096-ID range, with zero capabilities, an empty bounding set, no_new_privs, a 1-byte core dump limit, and KSM disabled (mergeable=off, PR_SET_MEMORY_MERGE cleared before exec and blocked by seccomp).
  • Double syscall and path confinement: Cloud Hypervisor's own --seccomp true and --landlock plus the daemon's seccomp denylist (refusing namespace calls, non-unix sockets, io_uring, mounts, ptrace, bpf, keyctl, userfaultfd, memfd_secret, KSM opt-in calls, admin calls, and alternate-architecture syscall tables). Hosts lacking seccomp or Landlock are refused at start.
  • Cgroup v2 and host-enforced disk I/O: each VM sits in its own cgroup with memory.max (guest RAM + 64 MiB + 8 MiB/GiB, memory.swap.max=0), pids.max, cpu.max, and kernel-enforced io.max (default 256 MiB/s and 16000 IOPS read/write, with a 1 GiB boot read budget).
  • Disk isolation: each VM gets a private 0600 block device node; the ZFS pool requires volmode=dev so the host kernel never scans guest partitions, and a udev noprobe rule is verified with a scratch volume at daemon startup.
  • Layered guest networking: per-run network namespace with unreachable routes (which hold even if firewall tables are flushed), nftables ingress and forwarding drop-by-default rules checked every 2 seconds, tbf bandwidth caps (default 200 Mbit/s), and ct count connection limits (default 4096).

Experimental memory snapshots, remote storage, and access

  • Memory snapshots (--vm-memory-snapshots, off by default): each memory image lives in its own encrypted ZFS dataset with a random 32-byte key wrapped under the host's secret (refused inside --state-dir). The dataset is unmounted and its key unloaded while stopped; restored VMs require a bound guest VM Generation ID driver so the kernel reseeds its PRNG before running.
  • Off-host storage (--remote-endpoint, off by default): chunks, manifests, and run records are encrypted client-side with AES-256-GCM using per-snapshot HKDF-SHA256 keys wrapped under the fleet master key. Key rotation re-wraps keys under a new master but does not rotate data keys (not a leak-recovery mechanism). Never roll an S3 bucket back while daemons are active.
  • Access listener (--access-addr, off by default): separated from the control API, requires mutual TLS 1.3 with distinct daemon and edge-client CAs (or Linux Unix socket peer-credential auth), and verifies Ed25519 grants (tsg1.*) against the run's strictly increasing access.epoch. Note that inbound access is not air-gapped: anyone holding a grant (or anyone on a public port) can move data in and out, and a client holding a stream open can relay traffic beyond the run's egress tier.