Skip to content

[Question] SandboxTemplate.environment environment variables not applied to container #863

Description

@derekhsu

Problem Description

When passing custom environment variables via SandboxSpec.template.environment, these variables do not appear in the sandbox container's environment.

Reproduction Steps

  1. Create a sandbox with environment variables using the Python SDK:
sandbox = client.create_sandbox(
    name="test-env",
    source="base",
    environment={
        "GATEWAY_URL": "http://10.156.113.180:8001",
        "GATEWAY_API_KEY": "test-key",
        "SANDBOX_ID": "test-env",
    },
)
  1. Debug output confirms the environment variables are correctly serialized in the protobuf message (request.spec.template.environment contains these values)

  2. After the sandbox is ready, run env inside the sandbox:

env | grep GATEWAY
# no output - environment variables are missing

Expected Behavior

Environment variables in template.environment should appear in the container's environment.

Actual Behavior

  • Debug output confirms template.environment is correctly passed to the OpenShell server
  • But running env shows no custom environment variables
  • OpenShell default environment variables (like OPENSHELL_SANDBOX_ID, SSL_CERT_FILE, etc.) do appear

Verification Steps Taken

  • prost protobuf serialization is correct: request.spec.template.environment contains all environment variables
  • Rust build_env_list function should process template_environment: it calls apply_env_map(&mut env, template_environment)
  • apply_env_map should upsert environment variables
  • Tested with a simple MY_TEST_VAR=test_value - same result, environment variable not present

Environment

Related Code

  • crates/openshell-server/src/sandbox/mod.rs:
    • sandbox_template_to_k8s receives template_environment: &HashMap<String, String>
    • build_env_list calls apply_env_map(&mut env, template_environment)
    • apply_env_map should upsert environment variables

Possible Causes

  1. prost deserialization issue with map<string, string> fields
  2. Kubernetes-level environment variable injection issue
  3. Or template.environment support was never fully implemented

Related issues: #848 (similar environment variable issue)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions