44from typing import Dict , Optional , TypedDict , overload
55from typing_extensions import Unpack
66
7- from e2b .connection_config import ConnectionConfig
7+ from e2b .connection_config import ConnectionConfig , ProxyTypes
88from e2b .envd .api import ENVD_API_HEALTH_ROUTE , ahandle_envd_api_exception
99from e2b .exceptions import format_request_timeout_error
1010from e2b .sandbox .main import SandboxSetup
@@ -106,7 +106,9 @@ def __init__(self, **opts: Unpack[AsyncSandboxOpts]):
106106 self ._envd_api_url = f"{ 'http' if self .connection_config .debug else 'https' } ://{ self .get_host (self .envd_port )} "
107107 self ._envd_version = opts ["envd_version" ]
108108
109- self ._transport = AsyncTransportWithLogger (limits = self ._limits )
109+ self ._transport = AsyncTransportWithLogger (
110+ limits = self ._limits , proxy = self ._connection_config .proxy
111+ )
110112 self ._envd_api = httpx .AsyncClient (
111113 base_url = self .envd_api_url ,
112114 transport = self ._transport ,
@@ -177,6 +179,7 @@ async def create(
177179 domain : Optional [str ] = None ,
178180 debug : Optional [bool ] = None ,
179181 request_timeout : Optional [float ] = None ,
182+ proxy : Optional [ProxyTypes ] = None ,
180183 ):
181184 """
182185 Create a new sandbox.
@@ -189,6 +192,7 @@ async def create(
189192 :param envs: Custom environment variables for the sandbox
190193 :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
191194 :param request_timeout: Timeout for the request in **seconds**
195+ :param proxy: Proxy to use for the request and for the **requests made to the returned sandbox**
192196
193197 :return: sandbox instance for the new sandbox
194198
@@ -199,6 +203,7 @@ async def create(
199203 domain = domain ,
200204 debug = debug ,
201205 request_timeout = request_timeout ,
206+ proxy = proxy ,
202207 )
203208
204209 if connection_config .debug :
@@ -214,6 +219,7 @@ async def create(
214219 debug = debug ,
215220 request_timeout = request_timeout ,
216221 env_vars = envs ,
222+ proxy = proxy ,
217223 )
218224 sandbox_id = response .sandbox_id
219225 envd_version = response .envd_version
@@ -231,13 +237,15 @@ async def connect(
231237 api_key : Optional [str ] = None ,
232238 domain : Optional [str ] = None ,
233239 debug : Optional [bool ] = None ,
240+ proxy : Optional [ProxyTypes ] = None ,
234241 ):
235242 """
236243 Connect to an existing sandbox.
237244 With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
238245
239246 :param sandbox_id: Sandbox ID
240247 :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
248+ :param proxy: Proxy to use for the request and for the **requests made to the returned sandbox**
241249
242250 :return: sandbox instance for the existing sandbox
243251
@@ -253,6 +261,7 @@ async def connect(
253261 api_key = api_key ,
254262 domain = domain ,
255263 debug = debug ,
264+ proxy = proxy ,
256265 )
257266
258267 return cls (
@@ -286,20 +295,25 @@ async def kill(
286295 domain : Optional [str ] = None ,
287296 debug : Optional [bool ] = None ,
288297 request_timeout : Optional [float ] = None ,
298+ proxy : Optional [ProxyTypes ] = None ,
289299 ) -> bool :
290300 """
291301 Kill the sandbox specified by sandbox ID.
292302
293303 :param sandbox_id: Sandbox ID
294304 :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
295305 :param request_timeout: Timeout for the request in **seconds**
306+ :param proxy: Proxy to use for the request
296307
297308 :return: `True` if the sandbox was killed, `False` if the sandbox was not found
298309 """
299310 ...
300311
301312 @class_method_variant ("_cls_kill" )
302- async def kill (self , request_timeout : Optional [float ] = None ) -> bool : # type: ignore
313+ async def kill (
314+ self ,
315+ request_timeout : Optional [float ] = None ,
316+ ) -> bool : # type: ignore
303317 config_dict = self .connection_config .__dict__
304318 config_dict .pop ("access_token" , None )
305319 config_dict .pop ("api_url" , None )
@@ -309,7 +323,7 @@ async def kill(self, request_timeout: Optional[float] = None) -> bool: # type:
309323
310324 await SandboxApi ._cls_kill (
311325 sandbox_id = self .sandbox_id ,
312- ** self . connection_config . __dict__ ,
326+ ** config_dict ,
313327 )
314328
315329 @overload
@@ -339,6 +353,7 @@ async def set_timeout(
339353 domain : Optional [str ] = None ,
340354 debug : Optional [bool ] = None ,
341355 request_timeout : Optional [float ] = None ,
356+ proxy : Optional [ProxyTypes ] = None ,
342357 ) -> None :
343358 """
344359 Set the timeout of the specified sandbox.
@@ -350,6 +365,7 @@ async def set_timeout(
350365 :param sandbox_id: Sandbox ID
351366 :param timeout: Timeout for the sandbox in **seconds**
352367 :param request_timeout: Timeout for the request in **seconds**
368+ :param proxy: Proxy to use for the request
353369 """
354370 ...
355371
@@ -369,7 +385,7 @@ async def set_timeout( # type: ignore
369385 await SandboxApi ._cls_set_timeout (
370386 sandbox_id = self .sandbox_id ,
371387 timeout = timeout ,
372- ** self . connection_config . __dict__ ,
388+ ** config_dict ,
373389 )
374390
375391 async def get_info ( # type: ignore
@@ -391,5 +407,5 @@ async def get_info( # type: ignore
391407
392408 return await SandboxApi .get_info (
393409 sandbox_id = self .sandbox_id ,
394- ** self . connection_config . __dict__ ,
410+ ** config_dict ,
395411 )
0 commit comments