Skip to content

Commit f582a57

Browse files
committed
fix: preserve internal env vars during /init EnvVars replacement
The EnvVars replace logic in SetData was deleting all keys from a.defaults.EnvVars that weren't present in the incoming customer config, including internal system vars like E2B_SANDBOX (set at startup), E2B_SANDBOX_ID, E2B_TEMPLATE_ID (set by MMDS polling), and E2B_EVENTS_ADDRESS (set by SetupHyperloop). Added isInternalEnvVar() helper to exclude these system-managed keys from deletion during the replace operation, ensuring they persist across /init calls.
1 parent d99c1d1 commit f582a57

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎packages/envd/internal/api/init.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ func (a *API) SetData(ctx context.Context, logger zerolog.Logger, data PostInitJ
188188

189189
// Replace, not merge: drop keys that are no longer present so a customer
190190
// who removes a variable from their config sees it actually removed.
191+
// Exclude internal env vars that are managed by the system.
191192
a.defaults.EnvVars.Range(func(key, _ string) bool {
192-
if _, keep := newVars[key]; !keep {
193+
if _, keep := newVars[key]; !keep && !isInternalEnvVar(key) {
193194
a.defaults.EnvVars.Delete(key)
194195
}
195196

@@ -397,6 +398,17 @@ func asString(v any) string {
397398
return s
398399
}
399400

401+
// isInternalEnvVar returns true for env vars that are managed by the system
402+
// and should not be deleted when customer env vars are replaced.
403+
func isInternalEnvVar(key string) bool {
404+
switch key {
405+
case "E2B_SANDBOX", "E2B_SANDBOX_ID", "E2B_TEMPLATE_ID", "E2B_EVENTS_ADDRESS":
406+
return true
407+
default:
408+
return false
409+
}
410+
}
411+
400412
func (a *API) SetupHyperloop(address string) {
401413
a.hyperloopLock.Lock()
402414
defer a.hyperloopLock.Unlock()

0 commit comments

Comments
 (0)