ALL INTELLIGENCE
蚂蚁 inclusionAI 官方仓库T1·Open Source

AKernel Open-Sources sandboxd with Four Runtime Backends

By inclusionAIOriginal title: ⭐ inclusionAI/sandboxd (5 stars)
58AI Score

The AKernel team has open-sourced sandboxd, a Linux sandbox lifecycle service that exposes a small gRPC API for starting, waiting on, inspecting, measuring and deleting sandboxes. It runs on gVisor, Kata Containers, Firecracker or an optional runc adapter, and bundles image management, cgroup and network resource allocation, and accelerator device leasing.

Full Report

Contents6 sections

sandboxd

sandboxd is the Linux sandbox lifecycle service used by AKernel. It exposes a small gRPC API, manages sandbox resources, and runs sandboxes with gVisor, Kata Containers, Firecracker, or the optional host-kernel runc adapter.

Responsibilities

  • Start, wait for, inspect, measure, and delete sandboxes.
  • Prepare local, OCI, Nydus, and S3-backed rootfs and mounts.
  • Extract and inject OCI image startup metadata for in-sandbox runtimes.
  • Allocate cgroups and pooled TAP or ephemeral veth endpoints, and configure iptables or eBPF for NAT.
  • Discover, validate, and lease scheduler-selected accelerator devices.

Architecture

TEXT
gRPC service
    |
sandbox lifecycle manager
    ├── sandbox runtime adapter ──> gVisor / Kata / Firecracker / runc
    ├── image manager ────────────> distill-fs / OCI
    └── resource managers ────────> cgroup / TAP or veth / iptables or eBPF

API / CLI

The public protobuf contract is api/runtime/v1/sandbox-api.proto. Runtime isolation, host requirements, and lifecycle differences are summarized in doc/runtime.md. The inherited OCI startup contract is documented in doc/image-process.md.

The sbox binary is an administrative CLI for managing sandboxes.

sbox list shows the runtime creation timestamp in CREATED and the elapsed time in AGE. For runsc, sandboxd reads creation time from its persisted container metadata because OCI state output does not include it. Unknown timestamps are shown as - rather than the Unix epoch; a future timestamp keeps its date but shows - for age.

NVIDIA GPU sandboxes

GPU support is experimental and currently uses gVisor runsc with nvproxy. The scheduler passes concrete node-local device IDs through StartRequest.xpu_allocations; sandboxd resolves them to NVIDIA UUIDs and maintains a local exclusive lease:

BASH
sbox start \
  --rootfs /path/to/directory-rootfs \
  --xpu-allocation gpu:0,2 \
  /bin/sleep 300

When [plugin.node_resource] is enabled, /resource includes the stable XPU inventory:

JSON
{"cpu":32,"mem":68719476736,"xpu":[{"type":"gpu","product_model":"l20","device_ids":[0,1]}]}

Kubernetes remains the default CPU and memory provider. A standalone process can report the effective limits of its own cgroup without Kubernetes access:

TOML
[plugin.node_resource]
provider = "cgroup"
sock_path = "/run/sandboxd/resource.sock"

The cgroup provider is read-only and works with both cgroup v1 and v2. It does not enable controllers or create child cgroups, including when experimental cgroup-disabled execution is selected.

See test/e2e/README.md for the validated GPU debug image and manual CUDA test.

OCI image cache

[plugin.image].oci_zero_ref_ttl configures node-wide retention of unreferenced OCI layers and lowerdirs. Omit it for the existing 30-minute TTL, or set it to "0s" to retain idle cache until disk-pressure GC needs the space. See OCI cache retention for configuration and cleanup semantics.

Network backends

Sandboxd supports two NAT backends:

  • iptables is the default backend.
  • bpfnat is an experimental embedded TC eBPF backend for Linux 5.10 or newer.

Select the backend with plugin.network.nat_backend. See the bpfnat implementation notes for its host prerequisites and build workflow.

Sandboxd owns TAP devices in the host network namespace whose names use its tap.<encoded-ip> format and decode to an address within plugin.network.ip_range. Startup recovery may reattach, reconfigure, and reuse those devices. Other software must not create TAP devices in this reserved namespace.

Sandboxd records the Linux boot ID alongside its metadata. A service restart in the same boot preserves active cgroup and TAP leases; missing or replaced active TAP devices still fail startup. When the boot ID changes, only the previous kernel's persisted cgroup and network lease caches are retired. Sandbox metadata, image-manager state, and checkpoint files remain available for normal reconciliation. An unstamped legacy store is adopted without discarding leases because a missing stamp does not prove a host reboot. This allows a worker's Pod to retain its identity across a reboot without treating vanished kernel resources as live; it does not restore sandbox processes or select a checkpoint automatically.

Before accepting RPCs, startup recovery also asks runsc to delete untracked records that explicitly report stopped with no positive process ID. This covers crashes that leave runtime state but no readable sandbox metadata. It uses the runtime's deletion boundary, preserves tracked records and live or ambiguous states, and fails startup on runtime inspection or cleanup errors. Other runtime adapters are unchanged.

Network ACL recovery also checks current runsc state. A tracked instance confirmed stopped without a positive PID no longer needs its old TAP binding restored; its metadata remains available for normal deletion. Persisted Running status alone is insufficient after a reboot. Live, missing, and ambiguous runtime states retain strict endpoint recovery, and an inspection error fails startup.

An optional per-sandbox ACL uses native netfilter and ipset with the iptables backend and TC eBPF with the bpfnat backend. Both support prioritized stateful IPv4 CIDR, domain, protocol, and port rules, fragments, and managed DNS policies. See the network ACL guide for its API, host requirements, limitations, and recovery behavior.

(注:更多技术实现细节与完整 API 文档请查阅原项目 README)