Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix connection to local envd

Jakub Novakdd9eb8507f50
diff --git a/packages/cli/test/filesystem.test.ts b/packages/cli/test/filesystem.test.ts
index df5b73531..cc6a43856 100644
--- a/packages/cli/test/filesystem.test.ts
+++ b/packages/cli/test/filesystem.test.ts
@@ -5,7 +5,7 @@ import * as e2bFs from '../src/utils/filesystem'
test('getFiles(): empty-dir', async () => {
const files = await e2bFs.getFiles(
- path.join(process.cwd(), 'test/fixtures/empty-dir'),
+ path.join(process.cwd(), 'test/fixtures/complementing-ignore-files'),
{ respectGitignore: true, respectDockerignore: true },
)
expect(files).toEqual([])
diff --git a/packages/js-sdk/src/sandbox/index.ts b/packages/js-sdk/src/sandbox/index.ts
index 74d1c1560..f41a786a5 100644
--- a/packages/js-sdk/src/sandbox/index.ts
+++ b/packages/js-sdk/src/sandbox/index.ts
@@ -428,7 +428,7 @@ export class Sandbox extends SandboxConnection {
* If a file with the same name already exists, it will be overwritten.
*/
get fileURL() {
- const protocol = this.getProtocol()
+ const protocol = this.getProtocol('http', this.opts.__debug_devEnv !== "local")
const hostname = this.getHostname(this.opts.__debug_port || ENVD_PORT)
return `${protocol}://${hostname}${FILE_ROUTE}`
}
diff --git a/packages/js-sdk/src/sandbox/sandboxConnection.ts b/packages/js-sdk/src/sandbox/sandboxConnection.ts
index cd4de3052..b5f9d26aa 100644
--- a/packages/js-sdk/src/sandbox/sandboxConnection.ts
+++ b/packages/js-sdk/src/sandbox/sandboxConnection.ts
@@ -193,10 +193,11 @@ export class SandboxConnection {
/**
* The function decides whether to use the secure or insecure protocol.
* @param baseProtocol Specify the specific protocol you want to use. Do not include the `s` in `https` or `wss`.
+ * @param secure Specify if you want to use the secure protocol
* @returns Protocol for the connection to the sandbox
*/
- getProtocol(baseProtocol: string = 'http') {
- return SECURE ? `${baseProtocol}s` : baseProtocol
+ getProtocol(baseProtocol: string = 'http', secure: boolean = SECURE) {
+ return secure ? `${baseProtocol}s` : baseProtocol
}
/**
@@ -375,7 +376,7 @@ export class SandboxConnection {
private async connectRpc() {
const hostname = this.getHostname(this.opts.__debug_port || ENVD_PORT)
- const protocol = this.getProtocol('ws')
+ const protocol = this.getProtocol('ws', this.opts.__debug_devEnv !== 'local')
const sandboxURL = `${protocol}://${hostname}${WS_ROUTE}`
let isFinished = false
diff --git a/packages/js-sdk/testground/local-envd.cjs b/packages/js-sdk/testground/local-envd.cjs
new file mode 100644
index 000000000..7da96ba3b
--- /dev/null
+++ b/packages/js-sdk/testground/local-envd.cjs
@@ -0,0 +1,27 @@
+const e2b = require('../dist')
+function wait(ms) {
+ return new Promise(resolve => setTimeout(resolve, ms))
+}
+
+async function main() {
+ const sandbox = await e2b.Sandbox.create({
+ id: 'base',
+ apiKey: process.env.E2B_API_KEY,
+ __debug_hostname: 'localhost',
+ __debug_port: 49982,
+ __debug_devEnv: "local"
+ })
+
+ await sandbox.filesystem.write(
+ '/code/hello.txt', "Hello World!"
+ )
+ const file = await sandbox.downloadFile('/code/hello.txt')
+
+ const enc = new TextDecoder("utf-8");
+ console.log(enc.decode(file))
+
+ await sandbox.close()
+}
+
+main().catch(console.error)
+
diff --git a/packages/python-sdk/e2b/sandbox/main.py b/packages/python-sdk/e2b/sandbox/main.py
index 8a4bcfb61..b343a5ecf 100644
--- a/packages/python-sdk/e2b/sandbox/main.py
+++ b/packages/python-sdk/e2b/sandbox/main.py
@@ -263,7 +263,7 @@ class Sandbox(SandboxConnection):
If a file with the same name already exists, it will be overwritten.
"""
hostname = self.get_hostname(self._debug_port or ENVD_PORT)
- protocol = self.get_protocol()
+ protocol = self.get_protocol(secure=self._debug_dev_env != "local")
file_url = f"{protocol}://{hostname}{FILE_ROUTE}"
diff --git a/packages/python-sdk/e2b/sandbox/sandbox_connection.py b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
index 71b2c71e3..5839dd2ea 100644
--- a/packages/python-sdk/e2b/sandbox/sandbox_connection.py
+++ b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
@@ -203,15 +203,16 @@ class SandboxConnection:
return hostname
@staticmethod
- def get_protocol(base_protocol: str = "http") -> str:
+ def get_protocol(base_protocol: str = "http", secure: bool = SECURE) -> str:
"""
The function decides whether to use the secure or insecure protocol.
:param base_protocol: Specify the specific protocol you want to use. Do not include the `s` in `https` or `wss`.
+ :param secure: Specify whether you want to use the secure protocol or not.
:return: Protocol for the connection to the sandbox
"""
- return f"{base_protocol}s" if SECURE else base_protocol
+ return f"{base_protocol}s" if secure else base_protocol
def keep_alive(self, duration: int) -> None:
"""
@@ -315,8 +316,9 @@ class SandboxConnection:
def _connect_rpc(self, timeout: Optional[float] = TIMEOUT):
hostname = self.get_hostname(self._debug_port or ENVD_PORT)
- protocol = self.get_protocol("ws")
+ protocol = self.get_protocol("ws", self._debug_dev_env != "local")
sandbox_url = f"{protocol}://{hostname}{WS_ROUTE}"
+
self._rpc = SandboxRpc(
url=sandbox_url,
on_message=self._handle_notification,