Replies: 2 comments 13 replies
GPU Sandbox Design ProposalMotivationGPU support is becoming increasingly important for AI, inference, model serving, media processing, and other accelerator-dependent workloads. For Cube Sandbox, the challenge is not only how to attach a GPU to a sandbox, but how to introduce accelerator support without weakening the existing design goals around isolation, lifecycle control, fast startup, and high-density deployment. GPU acceleration introduces several architectural trade-offs that should be made explicit from the beginning:
This proposal therefore treats GPU support as a layered design problem: first define a backend-agnostic accelerator abstraction, then use VFIO passthrough as the first reference implementation. Design GoalsThe initial design should aim to:
Non-goalsThe initial design does not aim to:
High-level ArchitectureThe proposed architecture has two layers. The first layer is a backend-agnostic accelerator abstraction. This layer describes accelerator requests, node capabilities, device allocation, attachment lifecycle, health state, compatibility metadata, and release semantics without assuming a specific implementation such as VFIO. The second layer is a pluggable backend implementation. In the initial phase, VFIO passthrough can serve as the reference backend because it provides strong isolation, clear ownership, and a useful baseline for performance and lifecycle behavior. The initial GPU flow should separate host initialization, template compatibility declaration, sandbox scheduling, MicroVM creation, device attachment, and in-guest validation:
This structure allows VFIO passthrough to be implemented first without making VFIO concepts the only possible long-term accelerator model. It also avoids placing unnecessary host-side preparation work on the MicroVM startup path and prevents incompatible hardware/kernel/runtime combinations from reaching a partially usable runtime state. Accelerator AbstractionThe generic accelerator model should describe what the sandbox needs, not how a particular backend satisfies it. A minimal abstraction may include:
The abstraction should avoid exposing VFIO-specific details in the user-facing model unless those details are required for explicit advanced configuration. For the first iteration, exclusive whole-device allocation is the simplest model. It avoids the scheduling and isolation complexity of shared-device backends while still giving the project a concrete implementation target. Host Initialization and Node-local Resource PreparationGPU-related host preparation should be completed as much as possible during host initialization, rather than being repeatedly handled by the MicroVM control plane at sandbox startup time. During host initialization, Cubelet should be responsible for:
This decouples host-side preparation from MicroVM lifecycle management. It can reduce sandbox startup overhead, simplify failure handling, and avoid runtime races where device preparation and MicroVM startup compete on the critical path. Host initialization should not imply that every GPU is immediately attached to a sandbox. It should only make devices visible, validated, and manageable by Cubelet. Pluggable Backend ModelDifferent accelerator backends may require different preparation, attachment, and cleanup logic. The design should make this backend boundary explicit. A backend should be responsible for:
The generic control plane should not need to know every detail of each backend. It should operate on common accelerator states and delegate backend-specific work to the selected implementation. This makes it possible to start with VFIO passthrough while leaving room for future GPU sharing, mediated devices, or API-forwarding approaches. VFIO Passthrough Reference ImplementationVFIO passthrough should be treated as the first reference implementation rather than the only possible GPU model. The VFIO backend can provide a baseline for:
For a VFIO-based sandbox:
This model intentionally favors correctness and isolation over density. It should be considered the “gold standard” baseline before introducing more complex sharing or virtualization schemes. Detailed Boundary: Cubelet VFIO Resource ModelCubelet should be the node-local owner of VFIO-backed GPU resources. Other components may participate in scheduling, attachment, and guest initialization, but the source of truth for physical GPU allocation on a node should remain in Cubelet. Resource OwnershipCubelet should own:
CubeShim should not own global VFIO allocation state. It should consume a device assignment created by Cubelet and report lifecycle information that helps Cubelet decide when a device can be safely released. CubeMaster should not manage individual device file descriptors or VFIO state. It should schedule based on abstract resource availability and compatibility metadata reported from nodes. Device State ModelA VFIO-backed GPU device may move through the following states:
The exact names can change during implementation, but the design should distinguish between “reserved,” “attached,” “releasing,” and “allocatable.” Treating these as the same state would make failure handling and reconciliation fragile. State Transition OverviewThe Cubelet VFIO resource model should be treated as a state machine rather than a set of independent flags. Each transition should have a single owner, explicit preconditions, and a clear failure target. A possible transition flow is:
The most important rule is that Cubelet should never transition a device back to State Transition RulesThe state machine should enforce the following rules:
These rules keep ownership simple: Cubelet owns node-local resource truth, CubeShim owns MicroVM attachment behavior, and CubeMaster owns cluster-level placement decisions. Failure Recovery PathsFailure handling should be defined around the lifecycle stage where the failure occurs. If reservation succeeds but MicroVM startup fails, Cubelet should:
If MicroVM startup succeeds but hot-plug fails, Cubelet should:
If hot-plug succeeds but guest initialization or compatibility validation fails, Cubelet should:
If sandbox teardown starts but CubeShim still holds VFIO file descriptors, Cubelet should:
If Cubelet restarts during an active GPU sandbox, it should reconstruct state from persisted reservations, runtime sandbox records, and host device state before advertising capacity again. Persistence and ReconciliationCubelet should persist enough information to recover VFIO resource ownership after restart or partial failure. Persisted reservation state may include:
After restart, Cubelet should reconcile persisted state with host reality before reporting capacity to CubeMaster. Reconciliation should check:
If persisted state and host reality disagree, Cubelet should prefer safety over availability. The device should remain unavailable until Cubelet can prove it is safe to reuse or an operator resolves the conflict. Events Reported to CubeMasterCubelet should report summarized accelerator state to CubeMaster without exposing unnecessary VFIO implementation details. Useful reportable information may include:
CubeMaster can use this information for scheduling and capacity awareness, while Cubelet remains the owner of detailed node-local VFIO state. Reservation RulesCubelet should reserve a device before MicroVM startup or device hot-plug begins. Reservation should record:
Reservation must be atomic from Cubelet’s local perspective. Once a device is reserved, no other sandbox on the same node should be able to consume it, even if VM startup has not happened yet. Release RulesCubelet should mark a device allocatable again only after all release conditions are satisfied. For the VFIO reference backend, release should require:
A conservative release path is preferred. A stale reservation is safer than incorrectly reassigning a device that is still busy. Reconciliation and Failure RecoveryCubelet should periodically reconcile its resource state with host reality. Reconciliation should cover:
Failure recovery should be conservative. If Cubelet cannot prove that a device is safe to reuse, it should move the device to quarantined or unhealthy rather than returning it to allocatable. Possible failure cases include:
Each failure case should have a clear target state and retry behavior. Monitoring and HealthCubelet should expose node-local accelerator health information to the scheduling layer. At minimum, health reporting should distinguish:
For the VFIO reference backend, health checks may include:
The health model should be generic enough that future GPU sharing or non-GPU accelerator backends can reuse it. Detailed Boundary: Template and Kernel CompatibilityGPU-backed sandboxes should be based on GPU-capable templates rather than extending CPU-only templates implicitly. The template should represent a compatibility contract between the requested accelerator resource and the guest runtime environment. GPU Template ContractA GPU-capable template should explicitly bind together:
This contract makes compatibility visible before sandbox startup. It also prevents CPU-only images from accumulating unnecessary GPU driver components. Guest Image SeparationGPU guest images should be separated from CPU-only guest images. This separation has several advantages:
GPU-capable images may be larger and more specialized. That trade-off should be explicit rather than hidden inside the default guest image. Guest Kernel SelectionThe system should support an instance or template specifying the guest kernel to use. This is necessary because GPU driver compatibility is often tied to:
A GPU template should not merely specify an image name. It should also specify the guest kernel and module package that are known to work with the selected GPU driver stack. Scheduling CompatibilityCubeMaster should consider template and kernel compatibility during scheduling. A GPU sandbox should only be placed on a node where:
This makes scheduling more than a “GPU count” decision. It becomes a compatibility match between device, backend, template, kernel, image, runtime, and memory requirements. Compatibility MetadataCompatibility metadata may include:
This metadata should remain abstract enough to support future non-NVIDIA accelerator types. Compatibility Validation and EnforcementCompatibility across GPU hardware, guest kernel drivers, and user-space driver/runtime stacks should be represented as an explicit compatibility contract. The goal is to fail early with a clear compatibility error if the selected hardware, template, kernel, modules, driver, or runtime stack cannot work together. The system should avoid starting a sandbox that reaches a partially usable GPU runtime state. Compatibility ContractA compatibility contract should bind together:
This contract can be attached to a GPU-capable template and matched against node-local hardware metadata reported by Cubelet. Validation StagesCompatibility should be validated in multiple stages. During host initialization, Cubelet should:
During template build or registration, GPU-capable templates should declare:
During scheduling, CubeMaster should:
During reservation and hot-plug, Cubelet should:
During guest startup, cube-agent should:
Enforcement BehaviorCompatibility validation should be enforced before the sandbox is considered ready. If validation fails before scheduling, CubeMaster should reject the placement. If validation fails during reservation or hot-plug preparation, Cubelet should reject the sandbox startup path and release or quarantine the device depending on whether the failure is safe and recoverable. If validation fails inside the guest, cube-agent should report the failure to the control plane. Cubelet should then decide whether to stop the sandbox, mark the startup as failed, release the device, or quarantine the device if the failure leaves the hardware state uncertain. The error should be explicit enough to identify which layer failed:
This staged validation model keeps compatibility checks close to the layer that owns the relevant information while still enforcing a single end-to-end compatibility contract. Detailed Boundary: Hot-plug LifecycleThe hot-plug lifecycle should define when a GPU device is attached, what must be true before attachment, and how failure should be handled. Lifecycle PhasesA GPU-backed sandbox using VFIO passthrough may follow this lifecycle:
This lifecycle keeps resource ownership in Cubelet while allowing CubeShim to focus on MicroVM attachment behavior. Preconditions for Hot-plugBefore GPU hot-plug begins, the following should be true:
If any of these conditions fail, the system should not attempt device hot-plug. Memory Allocation and PinningGPU device attachment may require stronger memory guarantees than CPU-only sandboxes. For GPU-capable MicroVMs, the design should require:
This may increase per-sandbox memory overhead and reduce density, but it avoids runtime instability and unpredictable GPU workload performance. Hot-plug Failure HandlingIf hot-plug fails, the system should recover without leaving the device in an ambiguous state. Possible actions include:
Cubelet should remain the component that decides whether the device can be reused. Teardown OrderingTeardown should follow a strict ordering:
This ordering should be treated as a lifecycle invariant for the VFIO reference implementation. Template and Device Hot-plug ModelGPU-backed sandboxes should preferably be based on templates rather than fully ad-hoc MicroVM construction at runtime. The template model should allow the system to predefine GPU-compatible VM configuration, guest image, guest kernel, runtime expectations, compatibility metadata, and validation behavior. Device attachment can then happen through a controlled hot-plug path when the sandbox is created or activated. This approach has several advantages:
When GPU devices are hot-plugged into a MicroVM, memory handling becomes important. GPU workloads should not rely on memory that may be swapped or lazily committed during device operation. For GPU-capable MicroVMs, the design should require:
This may increase per-sandbox memory overhead, but it improves stability and avoids runtime performance surprises for GPU workloads. Component ResponsibilitiesCubeMasterCubeMaster should own the cluster-level scheduling and resource accounting model. Its responsibilities may include:
CubeMaster should avoid embedding VFIO-specific assumptions directly into the scheduling model where a more generic accelerator abstraction is sufficient. CubeletCubelet should own node-local accelerator lifecycle management and should be the central manager for GPU VFIO resources. Its responsibilities may include:
Centralizing VFIO resource management in Cubelet provides consistent reservation, release, and monitoring behavior across the node. It also reduces the risk of resource conflicts between multiple local components. CubeShimCubeShim should attach the selected backend-specific device resources to the sandbox VM. For the VFIO reference backend, its responsibilities may include:
CubeShim should not own VFIO resource allocation globally. It should consume a device assignment made by Cubelet and report enough lifecycle information for Cubelet to release the resource safely. cube-agentcube-agent runs inside the guest and should handle guest-side initialization, compatibility validation, and diagnostics. Its responsibilities may include:
cube-agent should not be treated as the host-side accelerator inventory source. Guest Image, Guest Kernel, and Runtime StackGPU-backed sandboxes require a guest software stack that differs from CPU-only sandboxes. GPU guest images should include the required kernel and user-space driver components for the selected GPU stack. They should be separated from CPU-only guest images to avoid increasing storage consumption and image complexity for workloads that do not need GPU support. The guest side may need:
The system should support an instance or template specifying the guest kernel to use. This is necessary because GPU driver compatibility is often tied to specific kernel versions, module builds, and runtime libraries. In practice, GPU-capable templates should explicitly bind together:
This makes GPU compatibility part of the template contract rather than an implicit runtime assumption. Discovery, Scheduling, Allocation, and ReleaseDiscoveryNode-local accelerator discovery should identify enough information for scheduling and lifecycle management. At minimum, discovery should capture:
The inventory model should remain generic enough to support future accelerator types. SchedulingCubeMaster should treat accelerator requests as hard placement constraints. A sandbox that requests accelerators should only be scheduled to a node where:
For the first implementation, exclusive whole-device assignment should be assumed. AllocationAfter placement, Cubelet should reserve selected devices before MicroVM startup and backend attachment. Allocation metadata should include:
Reservation must happen before backend-specific attachment to avoid races with concurrent sandbox creation. ReleaseDevice release is not only a control-plane state transition. A device should be marked allocatable again only after:
A conservative release path is preferred. A stale allocation is safer than reallocating a device that is still busy. VFIO Lifecycle PitfallThe most important VFIO-specific operational risk is teardown ordering. For passthrough, the device may need to be rebound from the host driver to During teardown, releasing the device too early is unsafe if CubeShim still holds VFIO file descriptors or if VFIO unpin operations are still in progress. The VFIO backend and Cubelet should enforce the following invariant:
Violating this ordering can produce false-free devices, failed rebinds, or cross-sandbox interference on the next allocation. Cold-start and Performance Trade-offsGPU-backed sandboxes are expected to have different startup characteristics from CPU-only sandboxes. Cold-start latency may increase due to:
The design should reduce avoidable runtime overhead by moving host-side preparation into the host initialization phase. However, some GPU-specific costs will remain inherent to the sandbox startup or activation path. This trade-off should be treated as explicit product behavior. GPU-backed sandboxes may not preserve the same startup latency, high concurrency, or deployment density as CPU-only sandboxes. The design should make it clear that GPU support targets workloads where accelerator access is more important than extreme elasticity. Unsupported Lifecycle FeaturesThe initial GPU design should explicitly exclude lifecycle features that conflict with physical accelerator ownership or require major additional work. GPU-backed sandboxes should not initially support:
These limitations should be documented as expected behavior rather than hidden as edge cases. Deployment LimitationsThe VFIO reference implementation depends on PCI passthrough. Because PVM-based deployments cannot run guest VMs with passthrough PCI devices, PVM-based deployments are out of scope for the initial VFIO reference implementation. The first implementation should target environments where KVM and PCI passthrough are available and operationally supported. Extensibility for Future BackendsAlthough VFIO passthrough is the proposed reference implementation, the architecture should remain open to future backends. Possible future directions include:
To support that evolution, internal records, scheduling predicates, backend interfaces, template compatibility metadata, compatibility contracts, and node capability reporting should be accelerator-oriented rather than NVIDIA-only or VFIO-only. Open Questions
SummaryThis proposal frames GPU sandbox support as a layered accelerator design. The first layer is a backend-agnostic accelerator abstraction for API, scheduling, allocation, lifecycle, template compatibility, compatibility validation, and health management. The second layer is a pluggable backend model, with VFIO passthrough serving as the first reference implementation and baseline for isolation, performance, and lifecycle behavior. Compared with the previous draft, this version places more emphasis on detailed design boundaries. Cubelet should centrally own the VFIO resource state machine, including reservation, attachment state, release, reconciliation, health monitoring, failure recovery, quarantine, persistence, and node-local hardware capability reporting. GPU sandboxes should use GPU-specific templates that explicitly bind guest image, guest kernel, Compatibility should be enforced through a staged compatibility contract across host GPU hardware, guest kernel, The next step should be to refine these boundaries into concrete implementation-facing design items: the Cubelet VFIO resource state machine, the template/kernel/runtime compatibility contract, the compatibility validation flow, and the hot-plug lifecycle between Cubelet, CubeShim, and the guest. |
|
For GPU-enabled sandboxes, I would make the threat model explicit before finalizing the component split. GPU access changes the isolation boundary: the sandbox is no longer only CPU, filesystem, and network. It also includes device plugin behavior, driver surface, memory cleanup, scheduling fairness, and possible cross-workload leakage. Design points I would want captured in the proposal:
For AI agent workloads, I would also add a network/filesystem policy example with GPU enabled. In practice, the risky case is not just "can it use CUDA"; it is "can an untrusted model/tool use GPU plus filesystem plus network in the same execution boundary." |
Uh oh!
There was an error while loading. Please reload this page.
This discussion follows up on #111 and #160.
I originally opened #160 as a documentation PR, but based on maintainer feedback, I’m moving the proposal here first so the design can be discussed before becoming part of the docs.
The goal is to collect feedback on the scope, component responsibilities, lifecycle limitations, deployment limitations, and open questions before starting implementation work.
All reactions