Nothing, Deprecated #549
Closed
xiaojunxiang2023 wants to merge 1 commit into
Closed
Conversation
Treat Sandbox.create env_vars as sandbox runtime metadata and sync them into the guest at create/restore time through envd's native POST /init, so later commands.run / run_code can read them. No rootfs/profile writes, and per-command env precedence is preserved (create < per-command). - CubeAPI: serialize env_vars into the cube.master.sandbox.create_env_vars annotation instead of dropping them. - Cubelet: after the readiness probe, POST /init to <sandbox-ip>:49983 with the create env_vars (bounded retry, additive Store in envd); no shell / profile / rootfs mutation. - CubeMaster: forward the annotation (cube.master prefix) and strip it on template commit so per-instance secrets are not persisted into snapshots. Signed-off-by: xiaojunxiang <xiaojunxiang@kingsoft.com>
8678886 to
64d2f57
Compare
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make
env_varspassed toSandbox.create(...)visible to latercommands.run(...)/run_code(...), by treating them as sandbox runtimemetadata and syncing them into the guest through envd's native
POST :49983/initat create/restore time.This is an independent redesign of the previously rejected #484. It is based on
current
master(single commit, no dependency on #484) and drops therootfs/profile/bind-mount injection entirely, following the direction requested
in that review.
Background
Previously
env_varsfrom the SDK were dropped at the CubeAPI layer(
containers: vec![]), so they never reached the guest and were invisible tocommands.run. #484 tried to fix this by writing/etc/profile.d/99-cube-create-env.shinto the guest rootfs, which was rejectedas too hacky and not a runtime-layer solution.
Approach
env_varsare carried as runtime metadata and injected into envd, the same waythe upstream E2B orchestrator does it (
POST /init-> envddefaults.EnvVars).envd then merges them when it spawns any process, so the precedence
create env < per-command envholds for every process model, not just loginshells.
sandboxes.rs): serializeenv_varsinto thecube.master.sandbox.create_env_varsannotation (JSON object) instead ofdropping them.
cube.masterprefix passthrough, and stripped innormalizeStoredTemplateRequeston template commit so per-instance secretsare never persisted into template snapshots.
envd_init.go): after the readiness probe,POST /initto<sandbox-ip>:49983with the createenv_vars(bounded retry). envd storesthem additively (
defaults.EnvVars.Store), so env already present in theguest runtime (e.g. template env) is preserved.
No changes to envd (pinned
e2b-dev/infra@2026.16); this only wires up theclient side that CubeSandbox was missing compared to the official platform.
How this addresses the previous review
/init->defaults.EnvVars, merged at the exec layer for every spawned processexportoverrides per-commandenv=(broken precedence)defaults.EnvVarsfirst, per-command last -> per-command correctly overrides/bin/bash -l+/etc/profile.d, not generalPrecedence
template env < create env < per-command env.Template env already lives in the guest runtime today;
/initonly adds thecreate-time keys on top (same-key create overrides template), and envd's
per-command env still overrides both. Docker image
ENVis not surfaced tocommands.run, matching upstream envd behavior (see e2b-dev/infra#2268).Tests
Unit tests were added at every layer (all green):
envd_init_test.go: no-annotation no-op, invalid-JSON error,empty-IP error, success path asserting the
envVars/timestampsent to astub
/init, and retry-then-succeed.store_test.go:normalizeStoredTemplateRequeststrips thecreate-env annotation on commit while preserving unrelated annotations.
sandboxes.rs: annotation key uses thecube.masterprefix,absent/empty maps are skipped, and a non-empty map serializes to a JSON
object.
Build/format verified via the project toolchain:
cargo build/cargo test,go build/go vet, andgofmt+cargo fmtclean.Notes
/initbody only sendsenvVars+timestamp; all other fields areomitted, so it never clears envd's access token, default user/workdir, etc.
(CubeSandbox runs envd without an access token, so first-time
/initisauthorized.)
path runs the same probe + sync). Across pause/resume of the same VM the env
persists in guest memory, so no extra resume hook is required.