Summary
Create-time envs passed through Sandbox.create(envs=...) are not fully propagated to sandbox runtime execution.
On current origin/master, both commands.run and run_code miss those create-time envs. After applying the related CubeAPI-side fix, commands.run works, but run_code still does not.
This issue is a follow-up to #427. That earlier issue captured the broader propagation gap, and maintainer feedback there clarified that generic environment refresh at sandbox startup is not currently supported.
Environment
- CubeSandbox version / commit: current
origin/master
- Host OS and kernel version: Rocky Linux 9.6,
5.14.0-570.17.1.el9_6.x86_64
- KVM info (
modinfo kvm): host supports KVM; the issue is in the control/runtime integration path rather than KVM itself
- Deployment mode: cluster
- Relevant component: CubeAPI / sandbox runtime image / bundled lightweight code interpreter
Steps to Reproduce
- Create a sandbox through the E2B SDK with create-time envs on current
origin/master:
from e2b_code_interpreter import Sandbox
with Sandbox.create(
template="tpl-xxxx",
envs={"CUBE_TEST_CREATE": "from-e2b-create"},
) as sandbox:
print("commands.run:")
print(sandbox.commands.run("echo $CUBE_TEST_CREATE").stdout)
print("run_code:")
result = sandbox.run_code(
"import os; print(os.environ.get('CUBE_TEST_CREATE', '<NOT SET>'))"
)
print(result.logs.stdout)
- Observe the behavior of
commands.run and run_code.
Actual Behavior
On current origin/master:
commands.run:
run_code:
['<NOT SET>\n']
Both execution paths fail to see the create-time env var.
Related PR / Partial Verification
A separate CubeAPI-side PR is prepared for the CubeAPI -> envd propagation layer.
Related CubeAPI-side PR: #566
With that PR applied, the same script produces:
commands.run:
from-e2b-create
run_code:
['<NOT SET>\n']
So the related PR fixes the CubeAPI -> envd propagation layer for envd-backed command execution, such as commands.run.
The remaining gap is that run_code still does not inherit sandbox-level envs, because the bundled lightweight code interpreter in the sandbox image does not currently read envd /envs.
Additional Context
Verified split of the problem
The issue currently breaks down into two layers:
- CubeAPI create-path propagation
- runtime/image-side
run_code propagation
The related CubeAPI-side fix addresses the first layer by:
- accepting E2B SDK
envs as an alias of envVars
- posting create-time envs to envd after sandbox creation succeeds
That is enough to restore commands.run.
This keeps the follow-up narrowly scoped relative to #427: it does not claim that every runtime path now supports startup-time env refresh.
Why run_code still fails
run_code does not go through the same envd-backed command path as commands.run.
The bundled lightweight code interpreter in the sandbox image does not currently read sandbox-level envs from envd /envs, so even after envd has the correct values, run_code still prints <NOT SET>.
Verified behavior with the related CubeAPI-side fix
Cluster validation confirmed:
- E2B SDK
envs path works for commands.run
- CubeSandbox SDK native
envVars path also works for commands.run
- per-call command env overrides still work
- after a per-call override, the next
commands.run falls back to the sandbox-level env again
pause / resume preserves the same commands.run env visibility in the current lifecycle model
So for the currently verified lifecycle:
- a single create-time envd
/init call is sufficient for commands.run
- a separate resume-time re-init path does not appear necessary
Suggested follow-up direction
For the remaining run_code gap, the most direct follow-up appears to be updating the bundled lightweight code interpreter to read sandbox-level envs from envd /envs before applying per-call env overrides.
Preferred precedence:
sandbox-level envs from envd < per-call envs
Maintainer feedback requested
Would updating the bundled lightweight code interpreter to read envd /envs be the preferred follow-up direction for making run_code consistent with commands.run?
A separate CubeAPI-side fix is prepared for the first layer: propagating create-time envs into envd so that commands.run works correctly.
Summary
Create-time envs passed through
Sandbox.create(envs=...)are not fully propagated to sandbox runtime execution.On current
origin/master, bothcommands.runandrun_codemiss those create-time envs. After applying the related CubeAPI-side fix,commands.runworks, butrun_codestill does not.This issue is a follow-up to #427. That earlier issue captured the broader propagation gap, and maintainer feedback there clarified that generic environment refresh at sandbox startup is not currently supported.
Environment
origin/master5.14.0-570.17.1.el9_6.x86_64modinfo kvm): host supports KVM; the issue is in the control/runtime integration path rather than KVM itselfSteps to Reproduce
origin/master:commands.runandrun_code.Actual Behavior
On current
origin/master:Both execution paths fail to see the create-time env var.
Related PR / Partial Verification
A separate CubeAPI-side PR is prepared for the CubeAPI -> envd propagation layer.
Related CubeAPI-side PR: #566
With that PR applied, the same script produces:
So the related PR fixes the CubeAPI -> envd propagation layer for envd-backed command execution, such as
commands.run.The remaining gap is that
run_codestill does not inherit sandbox-level envs, because the bundled lightweight code interpreter in the sandbox image does not currently read envd/envs.Additional Context
Verified split of the problem
The issue currently breaks down into two layers:
run_codepropagationThe related CubeAPI-side fix addresses the first layer by:
envsas an alias ofenvVarsThat is enough to restore
commands.run.This keeps the follow-up narrowly scoped relative to #427: it does not claim that every runtime path now supports startup-time env refresh.
Why
run_codestill failsrun_codedoes not go through the same envd-backed command path ascommands.run.The bundled lightweight code interpreter in the sandbox image does not currently read sandbox-level envs from envd
/envs, so even after envd has the correct values,run_codestill prints<NOT SET>.Verified behavior with the related CubeAPI-side fix
Cluster validation confirmed:
envspath works forcommands.runenvVarspath also works forcommands.runcommands.runfalls back to the sandbox-level env againpause/resumepreserves the samecommands.runenv visibility in the current lifecycle modelSo for the currently verified lifecycle:
/initcall is sufficient forcommands.runSuggested follow-up direction
For the remaining
run_codegap, the most direct follow-up appears to be updating the bundled lightweight code interpreter to read sandbox-level envs from envd/envsbefore applying per-call env overrides.Preferred precedence:
Maintainer feedback requested
Would updating the bundled lightweight code interpreter to read envd
/envsbe the preferred follow-up direction for makingrun_codeconsistent withcommands.run?A separate CubeAPI-side fix is prepared for the first layer: propagating create-time envs into envd so that
commands.runworks correctly.