[Feature Request] Server-managed cube-envd injection for zero-friction template creation
Problem / Motivation
To run E2B-compatible sandboxes today, users typically need to build custom container images, either by basing their Dockerfile on cubesandboxbase or by manually installing and configuring an envd binary. This requirement creates significant friction when working with diverse upstream images at scale, such as in SWE-bench, SWE-gym, or Agent evaluation across heterogeneous environments.
PR #626 introduced an opt-in envd injection mechanism in cubemastercli to address this issue, allowing developer tooling to attach without manual Dockerfile modifications.
However, because the current implementation is built around client-side CLI binary uploads rather than a server-managed capability, it cannot be used in production or automated pipelines. This leaves several architectural limitations across the template and sandbox lifecycle:
1. API Semantic Asymmetry (CubeMaster vs. CubeAPI)
CubeMaster handles template creation (forwarded to TemplateCenter) and supports --enable-inject-envd via multipart/form-data to upload the local envd binary.
However, the user-facing CubeAPI service interacts with CubeMaster strictly via JSON (POST /cube/template/from-image in CubeAPI/src/cubemaster/mod.rs:392). When CubeMaster receives a JSON request with injection enabled, it rejects it (template_from_image_multipart.go:33):
envd injection requires multipart create-from-image uploadThis forces CubeAPI to omit the injection option entirely, making the feature inaccessible to SDK users and automated pipelines.
2. Redo Inability Due to Unpersisted Ephemeral Payloads
TemplateCenter is designed around reproducible ext4 rootfs builds and deterministic redo cycles (docs/dev/templatecenter-design.md §3.4).
However, the uploaded envd binary exists only in memory during the initial build job. While its SHA-256 hash contributes to the rootfs artifact fingerprint, the binary payload itself is never retained in TemplateCenter's artifact storage. When a template is rebuilt via redo, CubeMaster explicitly fails the job (templatecenter/redo.go:349):
redo cannot rebuild envd-enabled template rootfs because the original envd payload is not persisted3. Missing Envd Readiness Contract
When injection is enabled, CubeMaster wraps the container entrypoint to start envd in the background and exposes port 49983 (envd_sidecar.go:38). However, Cubelet (Cubelet/services/cubebox/probe.go:89) evaluates readiness solely through c.GetProbe():
- If the user omits
--probe,doProbetreats it as an immediate success without verifying thatenvdis listening. - If the user configures a probe for their application, Cubelet verifies only the application port, leaving
envdunverified.
In both cases, AppSnapshot is taken without validating that envd is healthy and listening on port 49983. Sandboxes restored from these templates can fail when external SDKs attempt to connect to port 49983.
4. Unmonitored Background Process & Shell Dependency
CubeMaster currently wraps the entrypoint by prepending a /bin/sh -c wrapper (envd_sidecar.go:42):
/usr/local/bin/envd >/var/log/envd.log 2>&1 & exec "$@"- Shell Dependency: This strictly requires
/bin/shto exist inside the guest image, which fails on distroless or minimal images. - Unmonitored Execution:
envdis launched as a detached background process (&) while the application becomes PID 1. Ifenvdexits or crashes during runtime (e.g., OOM or panic), it is neither monitored nor restarted. The sandbox remains reported as Running even though its SDK data-plane capabilities have permanently failed.
5. Lack of Architecture-Aware Binary Verification
Current payload validation (envd_inject.go:61) only checks that the first four bytes match \x7fELF. It does not inspect the ELF machine architecture (e_machine). Uploading an x86_64 binary for an arm64 image succeeds at build time and only fails at runtime with exec format error.
Proposed Solution
With the in-tree, pure-Rust cube-envd initiative (#1729, along with #1653 and #1504), CubeSandbox now maintains its own official, statically linked binary distribution. Managing cube-envd directly within TemplateCenter provides a natural evolution for the injection workflow, removing the need for client-side uploads.
This allows users to import arbitrary container images directly through CubeAPI or SDKs without Dockerfile modifications, manual binary downloads, or supervisor setup.
1. TemplateCenter Binary Ownership & Declarative JSON API
- Server-Managed Distribution: TemplateCenter provides official, self-contained, statically linked (
musl)cube-envdbinaries. Users no longer need to supply or upload an executable. - Unified JSON API: Add
inject_envd: booltoCubeAPIandCubeMasterJSON request schemas. CubeAPI passes this parameter directly without handling file uploads. - Deterministic Redo: TemplateCenter records the immutable digest of the injected
cube-envdartifact in the template metadata, allowingredoto reliably fetch the same binary and rebuild the rootfs. - Architecture Matching: TemplateCenter inspects the target OCI image manifest/platform and automatically selects the matching architecture binary (
amd64orarm64), resolving the CPU architecture mismatch problem without client intervention.
2. Built-in Envd Readiness for Injected Templates
Currently, cubebox.ContainerConfig only supports a single Probe field, which forces a choice between probing envd or the user application.
While a user could theoretically work around this by packaging a custom healthcheck wrapper inside their container to aggregate both port checks, doing so requires rebuilding the container and completely defeats the purpose of zero-touch injection on upstream images.
When inject_envd is enabled, the platform should take responsibility for verifying the injected daemon before AppSnapshot is taken:
- Built-in Envd Probe: Cubelet runs an internal readiness check against
http://<guest-ip>:49983/healthwith bounded timeout and retries. - Workload Probe: If the template also specifies a user application probe, Cubelet evaluates it alongside the
envdcheck. - Snapshot Gate:
AppSnapshotis captured only when all configured checks pass, ensuring bothenvdand the user application are ready.
(Alternatively, since CubeSandbox now owns cube-envd, the daemon itself could optionally be configured to aggregate user workload checks internally and surface combined status via its own /health endpoint.)
3. Robust In-Guest Startup & Failure Handling
To address shell dependency and unmonitored background execution:
- Avoid Shell Dependency: Avoid hard requirements on
/bin/shfor minimal/distroless environments (e.g., using a small static launcher or direct invocation). - Daemon Lifecycle Monitoring: Ensure unexpected exits or crashes of
cube-envdcan be detected or recovered, rather than silently leaving the sandbox in a degraded state where SDK commands fail.
4. Backward Compatibility
- Strictly Opt-In: The
inject_envdfeature remains an explicit opt-in setting (defaulting tofalse). Standard template builds and sandbox execution paths are completely unchanged when injection is not requested. - Pre-Baked Images Unaffected: Existing templates using
cubesandboxbaseor containing pre-baked/usr/local/bin/envdbinaries continue to work without modification. - CLI Upload Fallback:
cubemasterclican continue to accept local uploads as an override, converting the payload into a content-addressed storage object.
Source: TencentCloud/CubeSandbox