Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fixes Sandbox.connect not working when trying to pass API key via parameters (#772)

Mish Ushakov5c68eb7a250a
diff --git a/.changeset/flat-planets-build.md b/.changeset/flat-planets-build.md
new file mode 100644
index 000000000..10d71824a
--- /dev/null
+++ b/.changeset/flat-planets-build.md
@@ -0,0 +1,5 @@
+---
+'@e2b/python-sdk': patch
+---
+
+fixes minor regression where .connect would not succeed when passing API keys
diff --git a/packages/js-sdk/src/sandbox/index.ts b/packages/js-sdk/src/sandbox/index.ts
index cab6dae05..3bad2634d 100644
--- a/packages/js-sdk/src/sandbox/index.ts
+++ b/packages/js-sdk/src/sandbox/index.ts
@@ -456,7 +456,6 @@ export class Sandbox extends SandboxApi {
* @returns URL for downloading file.
*/
async downloadUrl(path: string, opts?: SandboxUrlOpts) {
- //path: string, useSignature?: boolean, signatureExpirationInSeconds?: number) {
opts = opts ?? {}
if (
diff --git a/packages/js-sdk/tests/api/info.test.ts b/packages/js-sdk/tests/api/info.test.ts
index 147dbae8b..0e3ca7c8e 100644
--- a/packages/js-sdk/tests/api/info.test.ts
+++ b/packages/js-sdk/tests/api/info.test.ts
@@ -1,9 +1,10 @@
import { expect } from 'vitest'
import { sandboxTest, isDebug } from '../setup.js'
+import { Sandbox } from '../../src'
sandboxTest.skipIf(isDebug)('get sandbox info', async ({ sandbox }) => {
- const info = await sandbox.getInfo()
+ const info = await Sandbox.getInfo(sandbox.sandboxId)
expect(info).toBeDefined()
expect(info.sandboxId).toBe(sandbox.sandboxId)
})
diff --git a/packages/python-sdk/e2b/sandbox_async/main.py b/packages/python-sdk/e2b/sandbox_async/main.py
index 324091de0..1bd0dd9fe 100644
--- a/packages/python-sdk/e2b/sandbox_async/main.py
+++ b/packages/python-sdk/e2b/sandbox_async/main.py
@@ -290,7 +290,13 @@ class AsyncSandbox(SandboxSetup, SandboxApi):
connection_headers = {}
- response = await SandboxApi.get_info(sandbox_id)
+ response = await SandboxApi._cls_get_info(
+ sandbox_id,
+ api_key=api_key,
+ domain=domain,
+ debug=debug,
+ proxy=proxy,
+ )
if response._envd_access_token is not None and not isinstance(
response._envd_access_token, Unset
@@ -430,6 +436,43 @@ class AsyncSandbox(SandboxSetup, SandboxApi):
**config_dict,
)
+ @overload
+ async def get_info(
+ self,
+ request_timeout: Optional[float] = None,
+ ) -> SandboxInfo:
+ """
+ Get sandbox information like sandbox ID, template, metadata, started at/end at date.
+ :param request_timeout: Timeout for the request in **seconds**
+ :return: Sandbox info
+ """
+ ...
+
+ @overload
+ @staticmethod
+ async def get_info(
+ sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ headers: Optional[Dict[str, str]] = None,
+ proxy: Optional[ProxyTypes] = None,
+ ) -> SandboxInfo:
+ """
+ Get sandbox information like sandbox ID, template, metadata, started at/end at date.
+ :param sandbox_id: Sandbox ID
+ :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+ :param domain: E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable
+ :param debug: Whether to use debug mode, defaults to `E2B_DEBUG` environment variable
+ :param request_timeout: Timeout for the request in **seconds**
+ :param headers: Custom headers to use for the request
+ :param proxy: Proxy to use for the request
+ :return: Sandbox info
+ """
+ ...
+
+ @class_method_variant("_cls_get_info")
async def get_info( # type: ignore
self,
request_timeout: Optional[float] = None,
@@ -447,7 +490,7 @@ class AsyncSandbox(SandboxSetup, SandboxApi):
if request_timeout:
config_dict["request_timeout"] = request_timeout
- return await SandboxApi.get_info(
+ return await SandboxApi._cls_get_info(
sandbox_id=self.sandbox_id,
**config_dict,
)
diff --git a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
index 8220f2a91..5cd737939 100644
--- a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
@@ -99,7 +99,7 @@ class SandboxApi(SandboxApiBase):
]
@classmethod
- async def get_info(
+ async def _cls_get_info(
cls,
sandbox_id: str,
api_key: Optional[str] = None,
diff --git a/packages/python-sdk/e2b/sandbox_sync/main.py b/packages/python-sdk/e2b/sandbox_sync/main.py
index 8b1f6a515..6dba662a9 100644
--- a/packages/python-sdk/e2b/sandbox_sync/main.py
+++ b/packages/python-sdk/e2b/sandbox_sync/main.py
@@ -142,7 +142,14 @@ class Sandbox(SandboxSetup, SandboxApi):
self._envd_version = None
self._envd_access_token = None
elif sandbox_id is not None:
- response = SandboxApi.get_info(sandbox_id)
+ response = SandboxApi._cls_get_info(
+ sandbox_id,
+ api_key=api_key,
+ domain=domain,
+ debug=debug,
+ request_timeout=request_timeout,
+ proxy=proxy,
+ )
self._sandbox_id = sandbox_id
self._envd_version = response.envd_version
@@ -408,6 +415,43 @@ class Sandbox(SandboxSetup, SandboxApi):
**config_dict,
)
+ @overload
+ def get_info(
+ self,
+ request_timeout: Optional[float] = None,
+ ) -> SandboxInfo:
+ """
+ Get sandbox information like sandbox ID, template, metadata, started at/end at date.
+ :param request_timeout: Timeout for the request in **seconds**
+ :return: Sandbox info
+ """
+ ...
+
+ @overload
+ @staticmethod
+ def get_info(
+ sandbox_id: str,
+ api_key: Optional[str] = None,
+ domain: Optional[str] = None,
+ debug: Optional[bool] = None,
+ request_timeout: Optional[float] = None,
+ headers: Optional[Dict[str, str]] = None,
+ proxy: Optional[ProxyTypes] = None,
+ ) -> SandboxInfo:
+ """
+ Get sandbox information like sandbox ID, template, metadata, started at/end at date.
+ :param sandbox_id: Sandbox ID
+ :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
+ :param domain: E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable
+ :param debug: Whether to use debug mode, defaults to `E2B_DEBUG` environment variable
+ :param request_timeout: Timeout for the request in **seconds**
+ :param headers: Custom headers to use for the request
+ :param proxy: Proxy to use for the request
+ :return: Sandbox info
+ """
+ ...
+
+ @class_method_variant("_cls_get_info")
def get_info( # type: ignore
self,
request_timeout: Optional[float] = None,
@@ -424,7 +468,7 @@ class Sandbox(SandboxSetup, SandboxApi):
if request_timeout:
config_dict["request_timeout"] = request_timeout
- return SandboxApi.get_info(
+ return SandboxApi._cls_get_info(
sandbox_id=self.sandbox_id,
**config_dict,
)
diff --git a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
index aa211c17f..fc5e9b134 100644
--- a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
@@ -95,7 +95,7 @@ class SandboxApi(SandboxApiBase):
]
@classmethod
- def get_info(
+ def _cls_get_info(
cls,
sandbox_id: str,
api_key: Optional[str] = None,
diff --git a/packages/python-sdk/tests/async/api_async/test_sbx_info.py b/packages/python-sdk/tests/async/api_async/test_sbx_info.py
index 18868fd7e..878a582c5 100644
--- a/packages/python-sdk/tests/async/api_async/test_sbx_info.py
+++ b/packages/python-sdk/tests/async/api_async/test_sbx_info.py
@@ -5,5 +5,5 @@ from e2b import AsyncSandbox
@pytest.mark.skip_debug()
async def test_get_info(async_sandbox: AsyncSandbox):
- info = await async_sandbox.get_info()
+ info = await AsyncSandbox.get_info(async_sandbox.sandbox_id)
assert info.sandbox_id == async_sandbox.sandbox_id
diff --git a/packages/python-sdk/tests/sync/api_sync/test_sbx_info.py b/packages/python-sdk/tests/sync/api_sync/test_sbx_info.py
index 095bfe367..e9b362ecc 100644
--- a/packages/python-sdk/tests/sync/api_sync/test_sbx_info.py
+++ b/packages/python-sdk/tests/sync/api_sync/test_sbx_info.py
@@ -5,5 +5,5 @@ from e2b import Sandbox
@pytest.mark.skip_debug()
def test_get_info(sandbox: Sandbox):
- info = sandbox.get_info()
+ info = Sandbox.get_info(sandbox.sandbox_id)
assert info.sandbox_id == sandbox.sandbox_id