Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix local debug mode

Tomas Valenta46d9e4ca67e4
diff --git a/packages/js-sdk/src/sandbox/sandboxConnection.ts b/packages/js-sdk/src/sandbox/sandboxConnection.ts
index b09c69a0c..ff0fa3588 100644
--- a/packages/js-sdk/src/sandbox/sandboxConnection.ts
+++ b/packages/js-sdk/src/sandbox/sandboxConnection.ts
@@ -305,7 +305,7 @@ export class SandboxConnection {
}
this.logger.debug?.('Opening sandbox...')
- if (!this.sandbox) {
+ if (!this.sandbox && !this.opts.__debug_hostname) {
try {
const res = await createSandbox(this.apiKey, {
envID: this.templateID,
@@ -335,7 +335,11 @@ export class SandboxConnection {
throw e
}
}
- this.refresh(this.sandbox.instanceID)
+
+ if (this.sandbox && !this.opts.__debug_hostname) {
+ this.refresh(this.sandbox.instanceID)
+ }
+
await this.connectRpc()
return this
}
diff --git a/packages/python-sdk/e2b/sandbox/sandbox_connection.py b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
index cf8d52636..961366e0f 100644
--- a/packages/python-sdk/e2b/sandbox/sandbox_connection.py
+++ b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
@@ -44,12 +44,12 @@ class SandboxConnection:
_on_close_child: Optional[Callable[[], Any]] = None
@property
- def id(self) -> str:
+ def id(self):
"""
The sandbox ID.
"""
if not self._sandbox:
- raise SandboxException("Sandbox is not running.")
+ return None
return f"{self._sandbox.instance_id}-{self._sandbox.client_id}"
@property
@@ -137,8 +137,6 @@ class SandboxConnection:
:return: Hostname of the sandbox or sandbox's port
"""
- if not self._sandbox:
- raise SandboxException("Sandbox is not running.")
if self._debug_hostname:
if port and self._debug_dev_env == "remote":
@@ -147,10 +145,15 @@ class SandboxConnection:
return f"{self._debug_hostname}:{port}"
else:
return self._debug_hostname
+ else:
+ if not self._sandbox:
+ raise SandboxException("Sandbox is not running.")
hostname = f"{self.id}.{SANDBOX_DOMAIN}"
+
if port:
return f"{port}-{hostname}"
+
return hostname
def keep_alive(self, duration: int) -> None:
@@ -211,7 +214,7 @@ class SandboxConnection:
else:
self._is_open = True
- if not self._sandbox:
+ if not self._sandbox and not self._debug_hostname:
try:
with E2BApiClient(api_key=self._api_key) as api_client:
api = client.InstancesApi(api_client)
@@ -240,7 +243,9 @@ class SandboxConnection:
self._close()
raise e
- self._start_refreshing()
+ if not self._debug_hostname:
+ self._start_refreshing()
+
try:
self._connect_rpc(timeout)
except Exception as e: