Skip to content

sdk: allow envs when connecting to a sandbox#1297

Open
FisherXZ wants to merge 4 commits intoe2b-dev:mainfrom
FisherXZ:feat/issue-1279-connect-envs
Open

sdk: allow envs when connecting to a sandbox#1297
FisherXZ wants to merge 4 commits intoe2b-dev:mainfrom
FisherXZ:feat/issue-1279-connect-envs

Conversation

@FisherXZ
Copy link
Copy Markdown

Summary

Closes #1279.

Extends POST /sandboxes/{sandboxID}/connect to accept optional environment variables, and wires them through the JS and Python SDKs.

  • Spec: added optional envVars field to ConnectSandbox in spec/openapi.yml; regenerated schema.gen.ts and connect_sandbox.py
  • JS SDK: added envs?: Record<string, string> to SandboxConnectOpts; serialized as envVars: opts?.envs in the POST body (matches create-time convention)
  • Python SDK: added envs: Optional[Dict[str, str]] = None to all three connect() overloads (sync + async) and both _cls_connect implementations; passed as env_vars=envs if envs is not None else UNSET so the field is absent from the wire payload when not supplied

Naming convention (consistent with create-time sandbox envs)

Layer Name
Public JS/Python API envs
OpenAPI wire field envVars
Python generated model env_vars

Usage

// JS
const sandbox = await Sandbox.connect(sandboxId, {
  envs: { GATEWAY_TOKEN: 'new-token' },
})
# Python
sandbox = Sandbox.connect(sandbox_id, envs={"GATEWAY_TOKEN": "new-token"})

Test plan

  • pnpm run typecheck passes in packages/js-sdk
  • pnpm run lint passes in packages/js-sdk
  • 4 unit tests added to configPropagation.test.ts — verify envs is forwarded when provided and absent when not
  • 2 unit tests added to each of tests/sync/sandbox_sync/test_config_propagation.py and tests/async/sandbox_async/test_config_propagation.py — verify env_vars propagation using monkeypatch
  • Live integration test deferred until backend ships connect-time env merge — existing connect.test.ts and test_connect.py cover the no-envs path

🤖 Generated with Claude Code

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

🦋 Changeset detected

Latest commit: 50d8641

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
e2b Minor
@e2b/python-sdk Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b40c88522e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

def connect(
sandbox_id: str,
timeout: Optional[int] = None,
envs: Optional[Dict[str, str]] = None,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle envs in sync class connect path

Adding envs to Sandbox.connect(sandbox_id, ...) exposes a runtime failure for class-style calls: when users call Sandbox.connect("...", envs={...}), the decorator routes to _cls_connect_sandbox, which does not declare envs, so envs stays inside opts and is later expanded into ConnectionConfig(..., **opts), raising TypeError for unexpected keyword envs. This makes the newly documented sync classmethod envs option unusable.

Useful? React with 👍 / 👎.

async def connect(
sandbox_id: str,
timeout: Optional[int] = None,
envs: Optional[Dict[str, str]] = None,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle envs in async class connect path

The async class-style API has the same regression: AsyncSandbox.connect("...", envs={...}) routes through _cls_connect_sandbox, which doesn't accept envs, so envs remains in opts and is passed to ConnectionConfig(..., **opts), causing TypeError: unexpected keyword argument 'envs'. As a result, the newly added async classmethod envs parameter fails at runtime.

Useful? React with 👍 / 👎.

FisherXZ and others added 4 commits April 27, 2026 23:30
Extends POST /sandboxes/{sandboxID}/connect to accept optional
environment variables. Field is optional, wire name envVars matches
create-time sandbox env convention.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds optional envs parameter to Sandbox.connect() in JS and Python SDKs.
Maps to envVars on the wire, matching create-time convention.
Uses UNSET (not None) in Python so the field is omitted when not supplied.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Matches the create-time pattern (envVars: opts?.envs) — openapi-fetch
strips undefined automatically so the conditional spread was unnecessary.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sandbox.connect(sandbox_id, envs=...) routed through _cls_connect_sandbox,
which lacked an explicit envs param. envs fell into **opts and was later
passed to ConnectionConfig(**opts), raising TypeError on the class-call path.

Added envs as an explicit param to both sync and async _cls_connect_sandbox
so it is forwarded to _cls_connect and kept out of the opts spread into
ConnectionConfig. Added regression tests covering the class-call path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@FisherXZ FisherXZ force-pushed the feat/issue-1279-connect-envs branch from f293a7e to 50d8641 Compare April 28, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow passing envs in POST /sandboxes/{id}/connect

1 participant