Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

feat(js-sdk): add proxy connection param (#1386)

Mish Ushakov4e16cffc2ff9
diff --git a/.changeset/js-sdk-proxy-param.md b/.changeset/js-sdk-proxy-param.md
new file mode 100644
index 000000000..241513352
--- /dev/null
+++ b/.changeset/js-sdk-proxy-param.md
@@ -0,0 +1,5 @@
+---
+"e2b": patch
+---
+
+Add `proxy` connection parameter to route SDK requests through an HTTP proxy, matching the Python SDK. When set, it applies to API requests, all requests made to the returned sandbox, and volume requests.
diff --git a/.changeset/volume-proxy-propagation.md b/.changeset/volume-proxy-propagation.md
new file mode 100644
index 000000000..609932767
--- /dev/null
+++ b/.changeset/volume-proxy-propagation.md
@@ -0,0 +1,6 @@
+---
+"@e2b/python-sdk": patch
+"e2b": patch
+---
+
+Fix `proxy` not being applied to volume content requests. `Volume.create`/`Volume.connect` now store the `proxy` on the returned instance, so instance methods (`list`, `readFile`, `writeFile`, `makeDir`, `getInfo`, `updateMetadata`, `remove`, …) route through it without having to pass `proxy` on every call. A per-call `proxy` still takes precedence.
diff --git a/packages/js-sdk/src/api/http2.ts b/packages/js-sdk/src/api/http2.ts
index 7bc4b92da..49bf1f6be 100644
--- a/packages/js-sdk/src/api/http2.ts
+++ b/packages/js-sdk/src/api/http2.ts
@@ -13,14 +13,20 @@ const DEFAULT_API_CONNECTION_LIMIT = 100
// Override via env if your workload needs different.
const DEFAULT_API_INFLIGHT_LIMIT = 1000
-let apiFetch: typeof fetch | undefined
+// Fetchers are cached per proxy so requests without a proxy keep sharing a
+// single dispatcher while each distinct proxy URL gets its own.
+const apiFetchers = new Map<string, typeof fetch>()
-export function createApiFetch(): typeof fetch {
- if (apiFetch) {
- return apiFetch
+export function createApiFetch(proxy?: string): typeof fetch {
+ const key = proxy ?? ''
+
+ const cached = apiFetchers.get(key)
+ if (cached) {
+ return cached
}
- apiFetch = createApiFetchForRuntime(runtime)
+ const apiFetch = createApiFetchForRuntime(runtime, { proxy })
+ apiFetchers.set(key, apiFetch)
return apiFetch
}
@@ -30,6 +36,7 @@ export function createApiFetchForRuntime(
options: {
connectionLimit?: number
inflightLimit?: number
+ proxy?: string
loadUndici?: () => Promise<UndiciModule | undefined>
} = {}
): typeof fetch {
@@ -50,6 +57,7 @@ export function createApiFetchForRuntime(
async function buildApiFetcher(options: {
connectionLimit?: number
inflightLimit?: number
+ proxy?: string
loadUndici?: () => Promise<UndiciModule | undefined>
}): Promise<typeof fetch> {
const undici = await (options.loadUndici ?? loadUndici)()
@@ -59,11 +67,18 @@ async function buildApiFetcher(options: {
return limitConcurrency(fetch, inflightLimit)
}
- const { Agent, fetch: undiciFetch } = undici
- const dispatcher = new Agent({
- allowH2: true,
- connections: options.connectionLimit ?? getApiConnectionLimit(),
- })
+ const { Agent, ProxyAgent, fetch: undiciFetch } = undici
+ const connections = options.connectionLimit ?? getApiConnectionLimit()
+ const dispatcher = options.proxy
+ ? new ProxyAgent({
+ uri: options.proxy,
+ allowH2: true,
+ connections,
+ })
+ : new Agent({
+ allowH2: true,
+ connections,
+ })
const fetchWithDispatcher = undiciFetch as unknown as (
input: RequestInfo | URL,
init?: UndiciRequestInit
diff --git a/packages/js-sdk/src/api/index.ts b/packages/js-sdk/src/api/index.ts
index afb6fe81d..ae4174bfb 100644
--- a/packages/js-sdk/src/api/index.ts
+++ b/packages/js-sdk/src/api/index.ts
@@ -95,7 +95,7 @@ class ApiClient {
this.api = createClient<paths>({
baseUrl: config.apiUrl,
- fetch: createApiFetch(),
+ fetch: createApiFetch(config.proxy),
// In HTTP 1.1, all connections are considered persistent unless declared otherwise
// keepalive: true,
headers: {
diff --git a/packages/js-sdk/src/connectionConfig.ts b/packages/js-sdk/src/connectionConfig.ts
index ef034fb3b..34d80d32d 100644
--- a/packages/js-sdk/src/connectionConfig.ts
+++ b/packages/js-sdk/src/connectionConfig.ts
@@ -69,6 +69,14 @@ export interface ConnectionOpts {
*/
headers?: Record<string, string>
+ /**
+ * Proxy URL to use for requests. In case of a sandbox it applies to all
+ * requests made to the returned sandbox.
+ *
+ * @example 'http://user:[email protected]:8080'
+ */
+ proxy?: string
+
/**
* Additional headers to send with E2B API requests.
*/
@@ -193,6 +201,8 @@ export class ConnectionConfig {
readonly headers?: Record<string, string>
+ readonly proxy?: string
+
constructor(opts?: ConnectionOpts) {
this.apiKey = opts?.apiKey || ConnectionConfig.apiKey
this.debug = opts?.debug || ConnectionConfig.debug
@@ -202,6 +212,7 @@ export class ConnectionConfig {
this.logger = opts?.logger
this.headers = { ...(opts?.headers ?? {}), ...(opts?.apiHeaders ?? {}) }
this.headers['User-Agent'] = `e2b-js-sdk/${version}`
+ this.proxy = opts?.proxy
this.apiUrl =
opts?.apiUrl ||
diff --git a/packages/js-sdk/src/envd/http2.ts b/packages/js-sdk/src/envd/http2.ts
index 0ddf59747..1de93db57 100644
--- a/packages/js-sdk/src/envd/http2.ts
+++ b/packages/js-sdk/src/envd/http2.ts
@@ -11,11 +11,14 @@ import {
type EnvdFetchOptions = {
connectionLimit?: number
inflightLimit?: number
+ proxy?: string
loadUndici?: () => Promise<UndiciModule | undefined>
}
-let envdFetch: typeof fetch | undefined
-let envdRpcFetch: typeof fetch | undefined
+// Fetchers are cached per proxy so requests without a proxy keep sharing a
+// single dispatcher while each distinct proxy URL gets its own.
+const envdFetchers = new Map<string, typeof fetch>()
+const envdRpcFetchers = new Map<string, typeof fetch>()
const DEFAULT_ENVD_CONNECTION_LIMIT = 10
const DEFAULT_ENVD_RPC_CONNECTION_LIMIT = 200
const DEFAULT_ENVD_INFLIGHT_LIMIT = 2000
@@ -49,13 +52,19 @@ async function buildEnvdFetcher(
return limitConcurrency(fetch, inflightLimit)
}
- const { Agent, fetch: undiciFetch } = undici
- const dispatcherOptions: { allowH2: true; connections?: number } = {
- allowH2: true,
- connections: options.connectionLimit ?? DEFAULT_ENVD_CONNECTION_LIMIT,
- }
-
- const dispatcher = new Agent(dispatcherOptions)
+ const { Agent, ProxyAgent, fetch: undiciFetch } = undici
+ const connections = options.connectionLimit ?? DEFAULT_ENVD_CONNECTION_LIMIT
+
+ const dispatcher = options.proxy
+ ? new ProxyAgent({
+ uri: options.proxy,
+ allowH2: true,
+ connections,
+ })
+ : new Agent({
+ allowH2: true,
+ connections,
+ })
const fetchWithDispatcher = undiciFetch as unknown as (
input: RequestInfo | URL,
init?: UndiciRequestInit
@@ -73,29 +82,39 @@ async function buildEnvdFetcher(
return limitConcurrency(wrapped, inflightLimit)
}
-export function createEnvdFetch(): typeof fetch {
- if (envdFetch) {
- return envdFetch
+export function createEnvdFetch(proxy?: string): typeof fetch {
+ const key = proxy ?? ''
+
+ const cached = envdFetchers.get(key)
+ if (cached) {
+ return cached
}
// Keep one origin connection for short envd REST calls. If ALPN falls back
// to h1, this favors connection pressure over per-sandbox throughput.
- envdFetch = createEnvdFetchForRuntime(runtime, {
+ const envdFetch = createEnvdFetchForRuntime(runtime, {
inflightLimit: getEnvdInflightLimit(),
+ proxy,
})
+ envdFetchers.set(key, envdFetch)
return envdFetch
}
-export function createEnvdRpcFetch(): typeof fetch {
- if (envdRpcFetch) {
- return envdRpcFetch
+export function createEnvdRpcFetch(proxy?: string): typeof fetch {
+ const key = proxy ?? ''
+
+ const cached = envdRpcFetchers.get(key)
+ if (cached) {
+ return cached
}
- envdRpcFetch = createEnvdFetchForRuntime(runtime, {
+ const envdRpcFetch = createEnvdFetchForRuntime(runtime, {
connectionLimit: getEnvdRpcConnectionLimit(),
inflightLimit: getEnvdRpcInflightLimit(),
+ proxy,
})
+ envdRpcFetchers.set(key, envdRpcFetch)
return envdRpcFetch
}
diff --git a/packages/js-sdk/src/sandbox/index.ts b/packages/js-sdk/src/sandbox/index.ts
index 918234176..9ffe8ae3c 100644
--- a/packages/js-sdk/src/sandbox/index.ts
+++ b/packages/js-sdk/src/sandbox/index.ts
@@ -159,8 +159,8 @@ export class Sandbox extends SandboxApi {
'E2b-Sandbox-Id': this.sandboxId,
'E2b-Sandbox-Port': this.envdPort.toString(),
}
- const envdFetch = createEnvdFetch()
- const envdRpcFetch = createEnvdRpcFetch()
+ const envdFetch = createEnvdFetch(this.connectionConfig.proxy)
+ const envdRpcFetch = createEnvdRpcFetch(this.connectionConfig.proxy)
const rpcTransport = createConnectTransport({
baseUrl: this.envdApiUrl,
diff --git a/packages/js-sdk/src/undici.ts b/packages/js-sdk/src/undici.ts
index 993d69f6f..e3566c0b4 100644
--- a/packages/js-sdk/src/undici.ts
+++ b/packages/js-sdk/src/undici.ts
@@ -5,6 +5,11 @@ export type UndiciRequestInit = RequestInit & {
export type UndiciModule = {
Agent: new (options: { allowH2: true; connections?: number }) => unknown
+ ProxyAgent: new (options: {
+ uri: string
+ allowH2: true
+ connections?: number
+ }) => unknown
fetch: unknown
}
diff --git a/packages/js-sdk/src/volume/client.ts b/packages/js-sdk/src/volume/client.ts
index bbe527e15..21bd4b361 100644
--- a/packages/js-sdk/src/volume/client.ts
+++ b/packages/js-sdk/src/volume/client.ts
@@ -2,6 +2,7 @@ import createClient from 'openapi-fetch'
import type { components, paths } from './schema.gen'
import { defaultHeaders, getEnvVar } from '../api/metadata'
+import { createApiFetch } from '../api/http2'
import { buildRequestSignal } from '../connectionConfig'
import { createApiLogger, Logger } from '../logs'
import type { Volume } from './index'
@@ -49,6 +50,13 @@ export interface VolumeApiOpts {
*/
headers?: Record<string, string>
+ /**
+ * Proxy URL to use for requests.
+ *
+ * @example 'http://user:[email protected]:8080'
+ */
+ proxy?: string
+
/**
* An optional `AbortSignal` that can be used to cancel the in-flight request.
* When the signal is aborted, the underlying `fetch` is aborted and the
@@ -66,6 +74,7 @@ export class VolumeConnectionConfig {
readonly logger?: Logger
readonly requestTimeoutMs?: number
readonly signal?: AbortSignal
+ readonly proxy?: string
constructor(volume: Volume, opts?: VolumeApiOpts) {
this.domain = opts?.domain || volume.domain || VolumeConnectionConfig.domain
@@ -79,6 +88,7 @@ export class VolumeConnectionConfig {
this.logger = opts?.logger
this.requestTimeoutMs = opts?.requestTimeoutMs
this.signal = opts?.signal
+ this.proxy = opts?.proxy || volume.proxy
}
private static get domain() {
@@ -110,6 +120,7 @@ class VolumeApiClient {
constructor(config: VolumeConnectionConfig) {
this.api = createClient<paths>({
baseUrl: config.apiUrl,
+ fetch: createApiFetch(config.proxy),
headers: {
...defaultHeaders,
...(config.token && { Authorization: `Bearer ${config.token}` }),
diff --git a/packages/js-sdk/src/volume/index.ts b/packages/js-sdk/src/volume/index.ts
index 747ce575d..bb655b1c6 100644
--- a/packages/js-sdk/src/volume/index.ts
+++ b/packages/js-sdk/src/volume/index.ts
@@ -65,6 +65,11 @@ export class Volume {
*/
readonly debug?: boolean
+ /**
+ * Proxy URL used for requests to the volume content API.
+ */
+ readonly proxy?: string
+
/**
* Create a local Volume instance with no API call.
*
@@ -73,19 +78,22 @@ export class Volume {
* @param token volume auth token.
* @param domain domain for the volume API.
* @param debug whether to use debug mode.
+ * @param proxy proxy URL for the volume content API.
*/
constructor(
volumeId: string,
name: string,
token: string,
domain?: string,
- debug?: boolean
+ debug?: boolean,
+ proxy?: string
) {
this.volumeId = volumeId
this.name = name
this.token = token
this.domain = domain
this.debug = debug
+ this.proxy = proxy
}
/**
@@ -121,7 +129,8 @@ export class Volume {
res.data.name,
res.data.token,
config.domain,
- config.debug
+ config.debug,
+ config.proxy
)
}
@@ -139,7 +148,14 @@ export class Volume {
): Promise<Volume> {
const config = new ConnectionConfig(opts)
const { name, token } = await Volume.getInfo(volumeId, opts)
- return new Volume(volumeId, name, token, config.domain, config.debug)
+ return new Volume(
+ volumeId,
+ name,
+ token,
+ config.domain,
+ config.debug,
+ config.proxy
+ )
}
/**
diff --git a/packages/js-sdk/tests/api/http2.test.ts b/packages/js-sdk/tests/api/http2.test.ts
index 6fb203c00..83ef5e421 100644
--- a/packages/js-sdk/tests/api/http2.test.ts
+++ b/packages/js-sdk/tests/api/http2.test.ts
@@ -38,6 +38,72 @@ test('uses undici with a bounded HTTP/2 dispatcher for API requests', async () =
expect(requests[0].init?.dispatcher).toBeInstanceOf(Agent)
})
+test('uses a ProxyAgent dispatcher when a proxy is configured', async () => {
+ const proxyAgents: Array<{
+ uri?: string
+ allowH2?: boolean
+ connections?: number
+ }> = []
+ const agents: Array<unknown> = []
+ const requests: Array<{ init?: RequestInit & { dispatcher?: unknown } }> = []
+
+ class Agent {
+ constructor() {
+ agents.push(this)
+ }
+ }
+
+ class ProxyAgent {
+ constructor(options: {
+ uri?: string
+ allowH2?: boolean
+ connections?: number
+ }) {
+ proxyAgents.push(options)
+ }
+ }
+
+ const undiciFetch = vi.fn((input, init) => {
+ requests.push({ init })
+ return Promise.resolve(new Response('ok'))
+ })
+ const loadUndici = vi.fn(() =>
+ Promise.resolve({ Agent, ProxyAgent, fetch: undiciFetch })
+ )
+
+ const { createApiFetchForRuntime } = await import('../../src/api/http2')
+
+ const fetcher = createApiFetchForRuntime('node', {
+ connectionLimit: 100,
+ proxy: 'http://user:[email protected]:8080',
+ loadUndici,
+ })
+ await fetcher('https://example.com/sandboxes')
+
+ expect(agents).toHaveLength(0)
+ expect(proxyAgents).toEqual([
+ {
+ uri: 'http://user:[email protected]:8080',
+ allowH2: true,
+ connections: 100,
+ },
+ ])
+ expect(requests[0].init?.dispatcher).toBeInstanceOf(ProxyAgent)
+})
+
+test('caches API fetchers per proxy', async () => {
+ const { createApiFetch } = await import('../../src/api/http2')
+
+ const noProxy = createApiFetch()
+ const proxyA = createApiFetch('http://127.0.0.1:8080')
+ const proxyB = createApiFetch('http://127.0.0.1:9090')
+
+ expect(createApiFetch()).toBe(noProxy)
+ expect(createApiFetch('http://127.0.0.1:8080')).toBe(proxyA)
+ expect(proxyA).not.toBe(noProxy)
+ expect(proxyA).not.toBe(proxyB)
+})
+
test('getApiConnectionLimit throws on a malformed env value', async () => {
process.env.E2B_API_CONNECTIONS = 'not-a-number'
diff --git a/packages/js-sdk/tests/envd/http2.test.ts b/packages/js-sdk/tests/envd/http2.test.ts
index fc8bfc40d..01ca90355 100644
--- a/packages/js-sdk/tests/envd/http2.test.ts
+++ b/packages/js-sdk/tests/envd/http2.test.ts
@@ -38,6 +38,73 @@ test('uses undici with HTTP/2 enabled in Node', async () => {
expect(requests[0].init?.dispatcher).toBeInstanceOf(Agent)
})
+test('uses a ProxyAgent dispatcher when a proxy is configured', async () => {
+ const proxyAgents: Array<{
+ uri?: string
+ allowH2?: boolean
+ connections?: number
+ }> = []
+ const agents: Array<unknown> = []
+ const requests: Array<{ init?: RequestInit & { dispatcher?: unknown } }> = []
+
+ class Agent {
+ constructor() {
+ agents.push(this)
+ }
+ }
+
+ class ProxyAgent {
+ constructor(options: {
+ uri?: string
+ allowH2?: boolean
+ connections?: number
+ }) {
+ proxyAgents.push(options)
+ }
+ }
+
+ const undiciFetch = vi.fn((input, init) => {
+ requests.push({ init })
+ return Promise.resolve(new Response('ok'))
+ })
+
+ const { createEnvdFetchForRuntime } = await import('../../src/envd/http2')
+
+ const fetcher = createEnvdFetchForRuntime('node', {
+ connectionLimit: 1,
+ proxy: 'http://127.0.0.1:8080',
+ loadUndici: () =>
+ Promise.resolve({ Agent, ProxyAgent, fetch: undiciFetch }),
+ })
+ await fetcher('https://example.com/status')
+
+ expect(agents).toHaveLength(0)
+ expect(proxyAgents).toEqual([
+ { uri: 'http://127.0.0.1:8080', allowH2: true, connections: 1 },
+ ])
+ expect(requests[0].init?.dispatcher).toBeInstanceOf(ProxyAgent)
+})
+
+test('caches envd fetchers per proxy', async () => {
+ const { createEnvdFetch, createEnvdRpcFetch } = await import(
+ '../../src/envd/http2'
+ )
+
+ const noProxy = createEnvdFetch()
+ const proxyA = createEnvdFetch('http://127.0.0.1:8080')
+
+ expect(createEnvdFetch()).toBe(noProxy)
+ expect(createEnvdFetch('http://127.0.0.1:8080')).toBe(proxyA)
+ expect(proxyA).not.toBe(noProxy)
+
+ const rpcNoProxy = createEnvdRpcFetch()
+ const rpcProxyA = createEnvdRpcFetch('http://127.0.0.1:8080')
+
+ expect(createEnvdRpcFetch()).toBe(rpcNoProxy)
+ expect(createEnvdRpcFetch('http://127.0.0.1:8080')).toBe(rpcProxyA)
+ expect(rpcProxyA).not.toBe(rpcNoProxy)
+})
+
test('passes Request objects to undici as URL plus init', async () => {
const requests: Array<{ input: RequestInfo | URL; init?: RequestInit }> = []
diff --git a/packages/js-sdk/tests/volume/volume.test.ts b/packages/js-sdk/tests/volume/volume.test.ts
index 87a1c0b92..404ccabad 100644
--- a/packages/js-sdk/tests/volume/volume.test.ts
+++ b/packages/js-sdk/tests/volume/volume.test.ts
@@ -4,6 +4,7 @@ import { setupServer } from 'msw/node'
import { randomUUID } from 'node:crypto'
import { Volume, NotFoundError } from '../../src'
+import { VolumeConnectionConfig } from '../../src/volume/client'
import { apiUrl } from '../setup'
// In-memory store for mock volumes
@@ -124,6 +125,30 @@ describe('Volume CRUD', () => {
)
})
+ it('should keep the proxy on the instance so content calls reuse it', async () => {
+ const proxy = 'http://user:[email protected]:8080'
+ const vol = await Volume.create('proxy-volume', { proxy })
+
+ // The proxy is stored on the instance...
+ expect(vol.proxy).toBe(proxy)
+
+ // ...and instance methods (which build a VolumeConnectionConfig with no
+ // per-call proxy) pick it up rather than falling back to no proxy.
+ const config = new VolumeConnectionConfig(vol)
+ expect(config.proxy).toBe(proxy)
+ })
+
+ it('should let a per-call proxy override the instance proxy', async () => {
+ const vol = await Volume.create('proxy-volume', {
+ proxy: 'http://127.0.0.1:8080',
+ })
+
+ const config = new VolumeConnectionConfig(vol, {
+ proxy: 'http://127.0.0.1:9090',
+ })
+ expect(config.proxy).toBe('http://127.0.0.1:9090')
+ })
+
it('should handle full lifecycle: create, get, list, destroy', async () => {
// Create
const vol = await Volume.create('lifecycle-vol')
diff --git a/packages/python-sdk/e2b/volume/volume_async.py b/packages/python-sdk/e2b/volume/volume_async.py
index d7533d291..c8932af9a 100644
--- a/packages/python-sdk/e2b/volume/volume_async.py
+++ b/packages/python-sdk/e2b/volume/volume_async.py
@@ -3,6 +3,7 @@ from http import HTTPStatus
import httpx
+from httpx._types import ProxyTypes
from typing_extensions import Unpack
from e2b.api import handle_api_exception
@@ -58,12 +59,14 @@ class AsyncVolume:
token: Optional[str] = None,
domain: Optional[str] = None,
debug: Optional[bool] = None,
+ proxy: Optional[ProxyTypes] = None,
):
self._volume_id = volume_id
self._name = name
self._token = token
self._domain = domain
self._debug = debug
+ self._proxy = proxy
@property
def volume_id(self) -> str:
@@ -87,7 +90,7 @@ class AsyncVolume:
api_url=opts.get("api_url"),
request_timeout=opts.get("request_timeout"),
headers=opts.get("headers"),
- proxy=opts.get("proxy"),
+ proxy=opts.get("proxy") if opts.get("proxy") is not None else self._proxy,
)
@classmethod
@@ -122,6 +125,7 @@ class AsyncVolume:
token=res.parsed.token,
domain=config.domain,
debug=config.debug,
+ proxy=config.proxy,
)
return vol
@@ -142,6 +146,7 @@ class AsyncVolume:
token=info.token,
domain=config.domain,
debug=config.debug,
+ proxy=config.proxy,
)
@staticmethod
diff --git a/packages/python-sdk/e2b/volume/volume_sync.py b/packages/python-sdk/e2b/volume/volume_sync.py
index b56ff31ba..94a4f5be6 100644
--- a/packages/python-sdk/e2b/volume/volume_sync.py
+++ b/packages/python-sdk/e2b/volume/volume_sync.py
@@ -3,6 +3,7 @@ from http import HTTPStatus
import httpx
+from httpx._types import ProxyTypes
from typing_extensions import Unpack
from e2b.api import handle_api_exception
@@ -58,12 +59,14 @@ class Volume:
token: Optional[str] = None,
domain: Optional[str] = None,
debug: Optional[bool] = None,
+ proxy: Optional[ProxyTypes] = None,
):
self._volume_id = volume_id
self._name = name
self._token = token
self._domain = domain
self._debug = debug
+ self._proxy = proxy
@property
def volume_id(self) -> str:
@@ -87,7 +90,7 @@ class Volume:
api_url=opts.get("api_url"),
request_timeout=opts.get("request_timeout"),
headers=opts.get("headers"),
- proxy=opts.get("proxy"),
+ proxy=opts.get("proxy") if opts.get("proxy") is not None else self._proxy,
)
@classmethod
@@ -122,6 +125,7 @@ class Volume:
token=res.parsed.token,
domain=config.domain,
debug=config.debug,
+ proxy=config.proxy,
)
return vol
@@ -142,6 +146,7 @@ class Volume:
token=info.token,
domain=config.domain,
debug=config.debug,
+ proxy=config.proxy,
)
@staticmethod
diff --git a/packages/python-sdk/tests/async/volume_async/test_volume.py b/packages/python-sdk/tests/async/volume_async/test_volume.py
index 4f80f8e10..af315e39a 100644
--- a/packages/python-sdk/tests/async/volume_async/test_volume.py
+++ b/packages/python-sdk/tests/async/volume_async/test_volume.py
@@ -133,6 +133,27 @@ async def test_get_info_nonexistent_volume():
await AsyncVolume.get_info("non-existent-id")
+async def test_create_volume_keeps_proxy_for_content_calls():
+ vol = await AsyncVolume.create(
+ "proxy-volume", proxy="http://user:[email protected]:8080"
+ )
+
+ # The proxy is stored on the instance...
+ assert vol._proxy == "http://user:[email protected]:8080"
+
+ # ...and instance methods (which build a VolumeConnectionConfig with no
+ # per-call proxy) pick it up rather than falling back to no proxy.
+ config = vol._get_volume_config()
+ assert config.proxy == "http://user:[email protected]:8080"
+
+
+async def test_volume_per_call_proxy_overrides_instance():
+ vol = await AsyncVolume.create("proxy-volume", proxy="http://127.0.0.1:8080")
+
+ config = vol._get_volume_config(proxy="http://127.0.0.1:9090")
+ assert config.proxy == "http://127.0.0.1:9090"
+
+
async def test_volume_full_lifecycle():
# Create
vol = await AsyncVolume.create("lifecycle-vol")
diff --git a/packages/python-sdk/tests/sync/volume_sync/test_volume.py b/packages/python-sdk/tests/sync/volume_sync/test_volume.py
index 331e767fa..fb9a1726d 100644
--- a/packages/python-sdk/tests/sync/volume_sync/test_volume.py
+++ b/packages/python-sdk/tests/sync/volume_sync/test_volume.py
@@ -133,6 +133,25 @@ def test_get_info_nonexistent_volume():
Volume.get_info("non-existent-id")
+def test_create_volume_keeps_proxy_for_content_calls():
+ vol = Volume.create("proxy-volume", proxy="http://user:[email protected]:8080")
+
+ # The proxy is stored on the instance...
+ assert vol._proxy == "http://user:[email protected]:8080"
+
+ # ...and instance methods (which build a VolumeConnectionConfig with no
+ # per-call proxy) pick it up rather than falling back to no proxy.
+ config = vol._get_volume_config()
+ assert config.proxy == "http://user:[email protected]:8080"
+
+
+def test_volume_per_call_proxy_overrides_instance():
+ vol = Volume.create("proxy-volume", proxy="http://127.0.0.1:8080")
+
+ config = vol._get_volume_config(proxy="http://127.0.0.1:9090")
+ assert config.proxy == "http://127.0.0.1:9090"
+
+
def test_volume_full_lifecycle():
# Create
vol = Volume.create("lifecycle-vol")