Skip to content

Add HTTPS_PROXY environment variable support to Python and JS SDKs#1270

Open
malthejorgensen wants to merge 2 commits intoe2b-dev:mainfrom
ferm-ai:add-https-proxy-envvar-support
Open

Add HTTPS_PROXY environment variable support to Python and JS SDKs#1270
malthejorgensen wants to merge 2 commits intoe2b-dev:mainfrom
ferm-ai:add-https-proxy-envvar-support

Conversation

@malthejorgensen
Copy link
Copy Markdown

@malthejorgensen malthejorgensen commented Apr 14, 2026

tl;dr Claude Code's web environment passes all requests through the proxy set in the environment variable HTTPS_PROXY. Since the E2B SDKs don't respect that variable, Claude Code on the web can't call the E2B APIs.

I've run formatters, linters and tests in both the Python and JS SDKs. As far as I can tell I'm only getting errors unrelated to this PR.

I've tested both the Python SDK and JS SDK in Claude Code web. Without this PR, Claude (on the web) is unable to interact with E2B sandboxes, and with this PR it is able to.

I'm more of a Python programmer. For the JS piece we need the Node official https://github.com/nodejs/undici to get the proxy support -- so it adds an extra dependency to the JS SDK.

This PR adds support for 6(!) different environment variables and I'd usually consider that AI slop, but it does seem to follow what other tools support (cURL, Python, and wget) with lowercase variables taking precedence: https://superuser.com/a/1690537

The code was generated with Claude Code, but I have read and tested it and made some smaller adjustments to both the JS SDK code and Python SDK code.

This adds support for the following proxy environment variables:

- https_proxy
- HTTPS_PROXY
- http_proxy
- HTTP_PROXY
- all_proxy
- ALL_PROXY

Lowercase version takes precedence as that seems to be standard across
cURL, Python, and wget -- yes, I agree -- it is nuts!

For a reference on the used environment variables and their
precedence see: https://superuser.com/a/1690537
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 14, 2026

⚠️ No Changeset found

Latest commit: 0019f61

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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: 6c37194891

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/js-sdk/src/proxy.ts Outdated

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { ProxyAgent } = require('undici')
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 Add undici dependency for proxy fetch path

getProxyFetch() relies on require('undici') to create ProxyAgent, but packages/js-sdk/package.json does not declare undici as a dependency, so typical installs of this SDK in Node will hit MODULE_NOT_FOUND and immediately fall back to plain fetch. In that scenario, setting HTTPS_PROXY/HTTP_PROXY has no effect, so the new proxy-support behavior is silently non-functional.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Add the undici dependency.

This adds support for the following proxy environment variables:

- https_proxy
- HTTPS_PROXY
- http_proxy
- HTTP_PROXY
- all_proxy
- ALL_PROXY

Lowercase version takes precedence as that seems to be standard across
cURL, Python, and wget -- yes, I agree -- it is nuts!

Adds the dependency `undici` which allows `fetch` requests to go through
a proxy. `undici` is owned by the Node.js organization
(https://github.com/nodejs/undici).

For a reference on the used environment variables and their
precedence see: https://superuser.com/a/1690537
@malthejorgensen malthejorgensen force-pushed the add-https-proxy-envvar-support branch from 6c37194 to 0019f61 Compare April 14, 2026 11:13
@malthejorgensen
Copy link
Copy Markdown
Author

Claude's own description of the PR:

Summary

  • Both SDKs use custom HTTP transports/clients that bypass the runtime's built-in proxy detection. This means standard proxy environment variables (HTTPS_PROXY, HTTP_PROXY, ALL_PROXY) are silently ignored, breaking the SDK for users behind corporate proxies.
  • Python SDK: Added _resolve_proxy() helper in connection_config.py that falls back to proxy env vars when no explicit proxy= is passed. Applied to all four transport factories (API async/sync, volume async/sync).
  • JS SDK: Added src/proxy.ts with getProxyFetch() that creates a proxy-aware fetch wrapper using undici's ProxyAgent (built into Node.js 20+). Applied to all four HTTP client locations (API client, envd API client, connect-rpc transport, volume client). Gracefully falls back to default fetch in browsers and edge runtimes.

Details

Why proxy env vars were ignored:

  • Python: httpx.AsyncClient(transport=...) skips env var proxy detection when a custom transport is provided. Since the SDK always uses a custom transport (for logging), proxies were never picked up.
  • JS: Node.js's built-in fetch does not respect HTTPS_PROXY/HTTP_PROXY at all — you must explicitly use undici's ProxyAgent.

Env vars checked (both SDKs): HTTPS_PROXY, https_proxy, HTTP_PROXY, http_proxy, ALL_PROXY, all_proxy

Explicit proxy= parameter (Python) still takes precedence over env vars.

Test plan

  • Set HTTPS_PROXY env var and verify Python SDK routes API and sandbox requests through the proxy
  • Set HTTPS_PROXY env var and verify JS SDK routes API and sandbox requests through the proxy
  • Verify both SDKs still work without any proxy env vars set (no behavioral change)
  • Verify explicit proxy= parameter in Python SDK takes precedence over env vars
  • Verify JS SDK degrades gracefully in browser environments (no errors, proxy not applied)

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.

1 participant