feat(cli): add --env flag to sandbox create/exec and fix env var passthrough#1730
Conversation
|
Label |
/ok to test fada35e |
PR Review StatusValidation: this PR is project-valid as a concentrated CLI/sandbox feature and bug fix for environment injection and passthrough. No exact duplicate was found. Review findings:
Docs: missing for direct UX changes. The new Tests/E2E: Next state: |
|
/ok to test fada35e |
CI Follow-UpBranch Checks failed on both Rust jobs at Branch E2E is still running, Helm Lint passed, and the PR remains in |
E2E ResultBranch E2E completed with one failing job: This does not look directly caused by the env-var changes from the current evidence, but the required E2E status is red. The PR remains in |
Fixes pushed in f190fa3Blocking: VM driver override-protectionRestructured Blocking: OPENSHELL_USER_ENVIRONMENT clobberableThree-layer defense:
Needs resolution:
|
|
/ok to test f190fa3 |
PR Review StatusValidation: this PR remains project-valid as a concentrated CLI/sandbox feature and bug fix for environment injection and passthrough. Review findings:
Docs: updated under Checks/E2E: Process blocker: GitHub currently reports Next state: |
f190fa3 to
cf1baf9
Compare
|
/ok to test cf1baf9 |
PR Review StatusValidation: this PR remains project-valid as a concentrated CLI/sandbox feature and bug fix for environment injection and passthrough. Review findings:
Docs: updated under Checks/E2E: Next state: |
CI Follow-UpRequired E2E completed for head The failing job is Please adjust the reserved-env validation so user-supplied Next state: |
Add `--env KEY=VALUE` (repeatable) to `openshell sandbox create` and `openshell sandbox exec`, wiring user-specified environment variables into the existing `SandboxSpec.environment` and `ExecSandboxRequest.environment` protobuf fields which were previously only accessible via the SDK/gRPC API. Fix a bug where user-specified environment variables set via `SandboxSpec.environment` were silently dropped inside sandbox SSH sessions. The SSH handler's `apply_child_env()` calls `env_clear()` to strip supervisor-internal secrets before spawning user shells, but this also wiped container-level env vars including user-specified ones. This was introduced in 5fd4885 (2026-02-26, "feat(sandbox): VS Code Remote-SSH support with platform detection fix") which added `env_clear()` to fix a VS Code platform detection timeout caused by leaked supervisor env vars. The fix introduces an `OPENSHELL_USER_ENVIRONMENT` sidecar env var: compute drivers (Docker, Podman, Kubernetes, VM) serialize the user-specified environment as JSON into this variable at container creation time, the sandbox supervisor deserializes it at startup, and the SSH handler re-injects the values into child processes after `env_clear()`. User-specified vars are applied at lowest priority so proxy, TLS, and provider credentials still take precedence. Signed-off-by: Russell Bryant <russell.bryant@gmail.com>
- VM driver: restructure build_guest_environment to apply user env before required driver vars, preventing user-specified values from overriding OPENSHELL_ENDPOINT, PATH, and other critical vars. Matches the pattern already used by Docker/Podman/Kubernetes. - All drivers: insert OPENSHELL_USER_ENVIRONMENT sidecar after environment.extend(user_env) so a user-supplied key of the same name cannot clobber the JSON payload the supervisor parses. - Podman driver: fix template/spec env precedence — template env is now applied first with spec overwriting, matching the other drivers (spec is user-specified and should win over image defaults). - CLI: add parse_env_pairs() that rejects OPENSHELL_* prefixed keys with a clear error message. Both sandbox create and exec call sites updated to use it. - SSH handler: filter out OPENSHELL_* keys from user_environment before injecting into child processes. - Docs: add "Set Environment Variables" section to manage-sandboxes.mdx documenting --env for both create and exec, per-command override semantics, and the OPENSHELL_* reservation. - Tests: add sandbox_create_env_rejects_reserved_prefix test. - Fix rustfmt formatting in lib.rs, container.rs, driver.rs.
Add server-side validation to reject environment variable keys starting with OPENSHELL_ in SandboxSpec.environment, SandboxTemplate.environment, and ExecSandboxRequest.environment. This closes the gap where SDK/gRPC callers (bypassing the CLI) could inject reserved keys that affect supervisor-internal state. The CLI already rejects these keys via parse_env_pairs, but the API boundary is the authoritative enforcement point since all clients (CLI, SDK, direct gRPC) pass through it.
Add POSIX env key format validation (^[A-Za-z_][A-Za-z0-9_]*$) and control character rejection for SandboxSpec.environment, SandboxTemplate.environment, and ExecSandboxRequest.environment at the gRPC validation layer. This catches invalid keys like "1BAD" or "BAD-NAME" and values containing newlines at the API boundary rather than letting them surface as driver-specific container/pod failures. Also add matching CLI-side validation in parse_env_pairs so users get immediate feedback. Update docs to say "OpenShell rejects" rather than "the CLI rejects" since enforcement is now at both boundaries.
cf1baf9 to
2f226e8
Compare
|
@gator-comment-pr1730.md |
@johntmyers looks like a gator bug :) |
|
/ok to test 2f226e8 |
Re-check After Author UpdateI re-evaluated latest head Disposition: partially resolved. The stray filename-only comment was a gator posting mistake; no author action was required for that comment. Remaining items:
Resolved from prior feedback: VM required-env precedence, Checks/E2E: Next state: |
CI Follow-UpRequired E2E completed for head The failing job is The PR remains in |
CI Follow-Up CorrectionI re-checked the failed E2E logs for head Correction to my previous CI note: I do not see the earlier The PR remains in
|
PR Review StatusValidation: this PR remains project-valid as a concentrated CLI/sandbox feature and bug fix for environment injection and passthrough. Independent review result: confirmed the current head still has blocking feedback. Review findings:
Docs: updated under Checks/E2E: Next state: |
Split exec env validation so OPENSHELL_PYFUNC_B64 (used by the Python SDK's exec_python()) passes through while runtime-clobberable keys like OPENSHELL_SANDBOX_ID are still rejected. Create-time validation remains strict — all OPENSHELL_* keys are blocked. Add a 256 KiB total serialized-size limit on create-time environment maps. The drivers serialize the full map into a single OPENSHELL_USER_ENVIRONMENT env var; capping the input at the API boundary prevents driver/runtime-specific startup failures from oversized env blocks. Add template environment control-character test and exec helper key acceptance test.
Re-check After Author UpdateI re-evaluated latest head Disposition: resolved for the blocking review feedback. The Python SDK Remaining items:
Docs: updated under Checks/E2E: Next state: |
|
/ok to test 69c18c7 |
Maintainer Approval NeededGator validation and PR monitoring are complete. Validation: this PR is project-valid as a concentrated CLI/sandbox feature and bug fix for sandbox environment injection and passthrough. Human maintainer approval or merge decision is now required. |
Summary
Add
--env KEY=VALUE(repeatable) toopenshell sandbox createandopenshell sandbox exec, and fix a bug where user-specified environment variables were silently dropped inside sandbox SSH sessions.Related Issue
N/A — discovered during investigation of env var injection support for sandboxes.
Changes
CLI (new feature):
--env KEY=VALUErepeatable flag tosandbox createandsandbox execsubcommandsparse_key_value_pairs()helper for consistent KEY=VALUE parsingSandboxSpec.environmentandExecSandboxRequest.environmentprotobuf fields (which were previously only accessible via the SDK/gRPC API)Sandbox env passthrough (bug fix):
apply_child_env()callsenv_clear()to strip supervisor secrets before spawning user shells, but this also wiped user-specified env vars set on the container by compute drivers. Introduced in 5fd4885 (2026-02-26, "feat(sandbox): VS Code Remote-SSH support with platform detection fix").OPENSHELL_USER_ENVIRONMENTsidecar env var: compute drivers serializeSandboxSpec.environmentas JSON, the supervisor deserializes it at startup, and the SSH handler re-injects the values afterenv_clear()Testing
cargo test -p openshell-cli— 18 tests pass (including 2 new: env passthrough + invalid format rejection)cargo testacross all modified crates — 1,252 tests passcargo clippyclean across all modified crates--env FOO=BARappears in sandboxenvoutputChecklist