Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Refactor

Jakub Novakf9169e588b6e
diff --git a/packages/js-sdk/src/sandbox/sandboxConnection.ts b/packages/js-sdk/src/sandbox/sandboxConnection.ts
index a0b223bef..7a3e156a0 100644
--- a/packages/js-sdk/src/sandbox/sandboxConnection.ts
+++ b/packages/js-sdk/src/sandbox/sandboxConnection.ts
@@ -315,7 +315,14 @@ export class SandboxConnection {
}
}
this.refresh(this.sandbox.instanceID)
- const hostname = this.getHostname(this.opts.__debug_port || ENVD_PORT)
+ await this.connectRpc()
+ return this
+ }
+ return await withTimeout(open, opts?.timeout)()
+ }
+
+ private async connectRpc() {
+ const hostname = this.getHostname(this.opts.__debug_port || ENVD_PORT)
if (!hostname) {
throw new Error('Cannot get sandbox\'s hostname')
@@ -404,11 +411,7 @@ export class SandboxConnection {
}
await openingPromise
- return this
- }
- return await withTimeout(open, opts?.timeout)()
}
-
private handleNotification(data: IRpcNotification) {
this.logger.debug?.('Handling notification:', data)
this.subscribers
diff --git a/packages/js-sdk/testground/basic.cjs b/packages/js-sdk/testground/basic.cjs
index f7e28aa7b..bd9524751 100644
--- a/packages/js-sdk/testground/basic.cjs
+++ b/packages/js-sdk/testground/basic.cjs
@@ -14,16 +14,14 @@ async function main() {
)
const sandboxID = sandbox.id
- await sandbox.keepAlive(60)
+ await sandbox.keepAlive(30)
await sandbox.close()
- await wait(20000)
+ await wait(15000)
const sandbox2 = await e2b.Sandbox.reconnect(sandboxID)
const files = await sandbox2.filesystem.read('/code/hello.txt')
- console.log(
- files
- )
+ console.log(files)
await sandbox2.close()
}
diff --git a/packages/python-sdk/e2b/templates/data_analysis.py b/packages/python-sdk/e2b/templates/data_analysis.py
index 6b9c43f1a..421598cde 100644
--- a/packages/python-sdk/e2b/templates/data_analysis.py
+++ b/packages/python-sdk/e2b/templates/data_analysis.py
@@ -1,11 +1,11 @@
import logging
import time
-from typing import Optional, Callable, Any, Tuple, List, Union, Literal
+from typing import Optional, Callable, Any, Tuple, List, Union
from e2b.sandbox.process import ProcessMessage
from pydantic import BaseModel, PrivateAttr
-from e2b import EnvVars, Sandbox, OpenPort
+from e2b import EnvVars, Sandbox
from e2b.constants import TIMEOUT
logger = logging.getLogger(__name__)
diff --git a/packages/python-sdk/example.py b/packages/python-sdk/example.py
index 84b699021..958744059 100644
--- a/packages/python-sdk/example.py
+++ b/packages/python-sdk/example.py
@@ -18,7 +18,7 @@ def main():
a = s.process.start("ls -la /home/user")
s.filesystem.write("/home/user/test.txt", "Hello World!")
a.wait()
- s.keep_alive(60)
+ s.keep_alive(30)
s.close()
sleep(20)