44from typing import Dict , Optional , TypedDict , overload
55from typing_extensions import Unpack
66
7+ from e2b .api .client .types import Unset
78from e2b .connection_config import ConnectionConfig
89from e2b .envd .api import ENVD_API_HEALTH_ROUTE , ahandle_envd_api_exception
910from e2b .exceptions import format_request_timeout_error
@@ -32,6 +33,7 @@ async def handle_async_request(self, request):
3233class AsyncSandboxOpts (TypedDict ):
3334 sandbox_id : str
3435 envd_version : Optional [str ]
36+ envd_access_token : Optional [str ]
3537 connection_config : ConnectionConfig
3638
3739
@@ -105,6 +107,7 @@ def __init__(self, **opts: Unpack[AsyncSandboxOpts]):
105107
106108 self ._envd_api_url = f"{ 'http' if self .connection_config .debug else 'https' } ://{ self .get_host (self .envd_port )} "
107109 self ._envd_version = opts ["envd_version" ]
110+ self ._envd_access_token = opts ["envd_access_token" ]
108111
109112 self ._transport = AsyncTransportWithLogger (limits = self ._limits )
110113 self ._envd_api = httpx .AsyncClient (
@@ -177,6 +180,7 @@ async def create(
177180 domain : Optional [str ] = None ,
178181 debug : Optional [bool ] = None ,
179182 request_timeout : Optional [float ] = None ,
183+ secure : Optional [bool ] = None ,
180184 ):
181185 """
182186 Create a new sandbox.
@@ -194,16 +198,12 @@ async def create(
194198
195199 Use this method instead of using the constructor to create a new sandbox.
196200 """
197- connection_config = ConnectionConfig (
198- api_key = api_key ,
199- domain = domain ,
200- debug = debug ,
201- request_timeout = request_timeout ,
202- )
201+ connection_headers = {"x" : "b" }
203202
204- if connection_config . debug :
203+ if debug :
205204 sandbox_id = "debug_sandbox_id"
206205 envd_version = None
206+ envd_access_token = None
207207 else :
208208 response = await SandboxApi ._create_sandbox (
209209 template = template or cls .default_template ,
@@ -214,13 +214,27 @@ async def create(
214214 debug = debug ,
215215 request_timeout = request_timeout ,
216216 env_vars = envs ,
217+ secure = secure ,
217218 )
218219 sandbox_id = response .sandbox_id
219220 envd_version = response .envd_version
221+ envd_access_token = response .envd_access_token
222+
223+ if envd_access_token is not None and not isinstance (envd_access_token , Unset ):
224+ connection_headers ["X-Access-Token" ] = envd_access_token
225+
226+ connection_config = ConnectionConfig (
227+ api_key = api_key ,
228+ domain = domain ,
229+ debug = debug ,
230+ request_timeout = request_timeout ,
231+ headers = connection_headers
232+ )
220233
221234 return cls (
222235 sandbox_id = sandbox_id ,
223236 envd_version = envd_version ,
237+ envd_access_token = envd_access_token ,
224238 connection_config = connection_config ,
225239 )
226240
@@ -255,9 +269,12 @@ async def connect(
255269 debug = debug ,
256270 )
257271
272+ response = await SandboxApi .get_info (sandbox_id )
273+
258274 return cls (
259275 sandbox_id = sandbox_id ,
260- envd_version = None ,
276+ envd_version = response .envd_version ,
277+ envd_access_token = response .envd_access_token ,
261278 connection_config = connection_config ,
262279 )
263280
0 commit comments