SDK: Add commands.setEnv syntactic sugar for runtime environment variable injection
Author: PangjipingCreated Sep 14, 2026Updated Sep 16, 2026
Labelshelp wantedsdks
Problem
Updating environment variables at runtime currently requires a raw shell command manipulating the internal $EXECD_ENVS file: await sandbox.commands.run("""printf '%s=%s\n' 'MY_TOKEN' 'value' >> "$EXECD_ENVS" """) Issues:
- Shell escaping risk — values with single quotes, backslashes, or special chars break the printf format string
- Implementation detail leak — users must know $EXECD_ENVS (internal execd concept)
- Inconsistent across languages — the shell snippet differs subtly between Python/Java/TS
- No validation — keys/values are raw strings in a shell command
Proposal
Add a setEnv method under the commands namespace:
await sandbox.commands.set_env("MY_TOKEN", "value")sandbox.commands().setEnv("MY_TOKEN", "value");await sandbox.commands.setEnv("MY_TOKEN", "value");Internally the SDK would: • Resolve $EXECD_ENVS path • Properly escape key/value (handle quotes, backslashes, newlines, = in values) • Append KEY=VALUE\n to the file via commands.run
Source: opensandbox-group/OpenSandbox