You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support undefined/null as unset in setEnvVars (#27609)
* Support undefined/null as unset in environment variable APIs
Document new behavior where undefined/null values in setEnvVars, exec options,
and session creation now unset variables instead of throwing errors.
- Add new 'Unsetting environment variables' section with examples
- Update type signatures to Record<string, string | undefined>
- Add examples showing undefined behavior in all env contexts
- Document use cases for conditional environment setup
Related to cloudflare/sandbox-sdk PR #342
* Fixed 3 minor issues across sandbox docs
Co-authored-by: elithrar <elithrar@users.noreply.github.com>
* Fix merge-damaged code indentation
Co-authored-by: elithrar <elithrar@users.noreply.github.com>
---------
Co-authored-by: OpenCode <opencode@anthropic.com>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: elithrar <elithrar@users.noreply.github.com>
Co-authored-by: Matt Silverlock <matt@eatsleeprepeat.net>
-`hostname` - Your Worker's domain name (e.g., `'example.com'`). Required to construct preview URLs with wildcard subdomains like `https://8080-sandbox-abc123token.example.com`. Cannot be a `.workers.dev` domain as it doesn't support wildcard DNS patterns.
31
31
-`name` - Friendly name for the port (optional)
32
-
-`token` - Custom token for the preview URL (optional). Must be 1-16 characters containing only lowercase letters (a-z), numbers (0-9), hyphens (-), and underscores (_). If not provided, a random 16-character token is generated automatically.
32
+
-`token` - Custom token for the preview URL (optional). Must be 1-16 characters containing only lowercase letters (a-z), numbers (0-9), hyphens (-), and underscores (\_). If not provided, a random 16-character token is generated automatically.
33
33
34
34
**Returns**: `Promise<ExposePortResponse>` with `port`, `url` (preview URL), `name`
**Use when:** You need isolated execution contexts with different environment variables running concurrently.
83
93
94
+
## Unsetting environment variables
95
+
96
+
The Sandbox SDK supports unsetting environment variables by passing `undefined` or `null` values. This enables idiomatic JavaScript patterns for managing configuration:
97
+
98
+
```typescript
99
+
awaitsandbox.setEnvVars({
100
+
// Set new values
101
+
API_KEY: 'new-key',
102
+
DATABASE_URL: env.DATABASE_URL,
103
+
104
+
// Unset variables (removes them from the environment)
105
+
OLD_API_KEY: undefined,
106
+
TEMP_TOKEN: null
107
+
});
108
+
```
109
+
110
+
**Before this change**: Passing `undefined` values would throw a runtime error.
111
+
112
+
**After this change**: `undefined` and `null` values run `unset VARIABLE_NAME` in the shell.
"logs": "Done! I've removed the brain emoji from the README title. The heading now reads \"# Cloudflare Agents\" instead of \"# 🧠 Cloudflare Agents\".",
"logs": "Done! I've removed the brain emoji from the README title. The heading now reads \"# Cloudflare Agents\" instead of \"# 🧠 Cloudflare Agents\".",
0 commit comments