How CubeSandbox Ensures OCI Compatibility: Runtime, Image, and Networking Layers

CubeSandbox ensures OCI compatibility by directly consuming OCI runtime specifications, encoding network extensions as OCI annotations, and unpacking OCI image layouts using the reference umoci tooling.

TencentCloud/CubeSandbox is an open-source container runtime that guarantees OCI (Open Container Initiative) compliance across its entire stack. Unlike systems that translate proprietary formats, CubeSandbox operates natively on OCI specs—from the runtime JSON that defines container execution to the image layout format used for storage. This architecture ensures seamless interoperability with standard container tools like Docker, containerd, and CRI-O.

OCI Runtime Specification Loading

At startup, CubeSandbox’s CRI plugin initializes by loading and validating OCI runtime specifications provided by users or default configurations.

Base Spec Loading and Caching

In Cubelet/plugins/cube/runtime/plugin.go, the system implements two critical functions: loadBaseOCISpecs and loadOCISpec. The loadBaseOCISpecs function reads a user-provided base OCI spec file and validates it against the OCI schema, returning a map of *oci.Spec objects. These specs are cached in the runtime.baseOCISpecs map, making them available to other components throughout the container lifecycle.

// Load base OCI specs from configuration
ociSpec, err := loadBaseOCISpecs(&cfg)   // Returns map[string]*oci.Spec

This cached specification serves as the foundation for all subsequent container creation operations, ensuring that every container starts with a standards-compliant runtime configuration.

OCI-Compatible Networking Layer

CubeSandbox extends OCI specs through annotations rather than breaking the specification, maintaining compatibility with standard runtimes while adding networking capabilities.

Network Configuration as OCI Annotations

In Cubelet/network/proto/network.go, the method OCISpecOpts() converts internal networking requests into OCI-compatible spec options. Specifically, it serializes the ShimNetReq structure and injects it into the OCI spec under the annotation key annotations.cubelet.network.

// Convert network request to OCI spec options
netOpts := shimReq.OCISpecOpts()  // Returns oci.SpecOpts

When the containerd shim receives the final OCI spec, it contains this networking metadata in standard annotation format, allowing the underlying OCI runtime to process the configuration without requiring CubeSandbox-specific modifications.

OCI Image Layout and Unpacking

CubeSandbox handles container images using the OCI Image Specification layout format, ensuring that pulled images remain compatible with standard registry tools and runtime implementations.

Creating OCI Layouts

The file CubeMaster/pkg/templatecenter/image/export.go handles image materialization by first creating an OCI layout directory structure on disk. This layout conforms exactly to the OCI Image Specification, storing manifests, configs, and layer blobs in the standardized directory format.

Rootless Unpacking with umoci

After creating the layout, CubeSandbox invokes umoci unpack --rootless—the same reference implementation used by the OCI community—to convert the layout into a runnable container bundle. This approach guarantees that the unpacked bundle structure matches what any OCI-compliant runtime expects.

// Pull OCI image and materialize as bundle
layoutDir, err := image.ExportOCIlayout(ctx, imgRef) // Creates OCI layout
bundleDir, err := image.UnpackWithUmoci(layoutDir)   // Runs "umoci unpack --rootless"

Native Layer Streaming

For direct layer handling, CubeMaster/pkg/templatecenter/image/native.go fetches OCI image layers and streams them into a directory that conforms to the OCI layout schema. This allows CubeSandbox to work with OCI layers directly without intermediate translation, preserving content-addressable storage integrity.

CRI API OCI Configuration

CubeSandbox’s CRI (Container Runtime Interface) API exposes OCI configuration directly through Protocol Buffer definitions, ensuring that container configurations remain transparent and standards-compliant.

Protobuf OCIConfig Definition

In Cubelet/api/services/cubebox/v1/cubebox.pb.go, the OCIConfig message mirrors the fields of the standard OCI runtime specification, including devices, CDI devices, and other runtime parameters. This protobuf definition is embedded within ContainerConfig, allowing the CRI API to transport OCI-compliant configurations between CubeSandbox components.

The OCIConfig structure ensures that when clients request container operations, they are working with data structures that map directly to the OCI spec fields defined in the Open Container Initiative standards.

Integration Flow: From Image to Running Container

Understanding how CubeSandbox ensures OCI compatibility requires examining how these components interact:

  1. Runtime Initialization: When the CRI plugin starts (Cubelet/plugins/cube/runtime/plugin.go), it loads the base OCI spec into memory, caching it as *oci.Spec objects in runtime.baseOCISpecs.

  2. Network Injection: During container creation, networking requirements are converted via OCISpecOpts() into OCI annotations, extending the spec without breaking compatibility.

  3. Image Materialization: The template engine pulls OCI image references and creates a standard OCI layout on disk, then uses umoci to unpack the root filesystem—producing a bundle that any OCI runtime can execute.

  4. Spec Assembly: The final OCI spec combines the cached base configuration, network annotations, and user-defined options, then passes to the containerd shim as a standards-compliant JSON document.

This pipeline ensures that every container launched by CubeSandbox adheres to OCI standards at every stage—from the image blobs on disk to the runtime JSON processed by the low-level container runtime.

Summary

Frequently Asked Questions

What is OCI compatibility and why does it matter for CubeSandbox?

OCI compatibility means that CubeSandbox adheres to the Open Container Initiative specifications for both container images and runtime configurations. This matters because it ensures containers created by CubeSandbox can run on any OCI-compliant runtime (such as Docker, containerd, or CRI-O) and that standard container images work without modification. The implementation uses the official umoci tool for unpacking and maintains OCI layout structures throughout the image lifecycle.

How does CubeSandbox handle networking without breaking OCI spec compliance?

CubeSandbox encodes network configuration as OCI annotations using the OCISpecOpts() method in Cubelet/network/proto/network.go. Rather than modifying the OCI spec structure itself, it injects the serialized ShimNetReq under the annotations.cubelet.network key. This approach follows the OCI specification’s extension mechanism, allowing the runtime to pass additional metadata while remaining fully compatible with standard OCI runtimes that can ignore unknown annotations.

What specific files handle OCI image unpacking in CubeSandbox?

The OCI image handling is split between two main files in CubeMaster/pkg/templatecenter/image/: export.go creates the OCI layout directory and invokes umoci unpack --rootless to generate runnable bundles, while native.go handles direct streaming of OCI layers into layout-conforming directories. Together, these files ensure that CubeSandbox works with images using the same content-addressable storage and layer formats defined by the OCI Image Specification.

How does the CRI API maintain OCI configuration standards?

The CRI API uses Protocol Buffer definitions in Cubelet/api/services/cubebox/v1/cubebox.pb.go that include an OCIConfig message type. This message mirrors the fields of the standard OCI runtime spec, including devices and CDI configurations. By embedding OCIConfig within ContainerConfig, the API ensures that all container configuration data transmitted between CubeSandbox components maps directly to OCI specification fields, eliminating translation layers that could introduce incompatibilities.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →