Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Handle paths properly on windows (#174)

Jakub Novák467082ca46d2
diff --git a/packages/js-sdk/src/utils/filesystem.ts b/packages/js-sdk/src/utils/filesystem.ts
index 9e05a4286..748b5933b 100644
--- a/packages/js-sdk/src/utils/filesystem.ts
+++ b/packages/js-sdk/src/utils/filesystem.ts
@@ -8,7 +8,7 @@ export const resolvePath = (
): string => {
let result: string
if (inputPath.startsWith('./')) {
- result = path.join(cwd || '/home/user', inputPath)
+ result = path.posix.join(cwd || '/home/user', inputPath)
if (!cwd) {
logger.warn?.(
`Path starts with './' and cwd isn't set. The path '${inputPath}' will evaluate to '${result}', which may not be what you want.`,
@@ -18,7 +18,7 @@ export const resolvePath = (
}
if (inputPath.startsWith('../')) {
- result = path.join(cwd || '/home/user', inputPath)
+ result = path.posix.join(cwd || '/home/user', inputPath)
if (!cwd) {
logger.warn?.(
`Path starts with '../' and cwd isn't set. The path '${inputPath}' will evaluate to '${result}', which may not be what you want.`,
@@ -27,7 +27,7 @@ export const resolvePath = (
return result
}
if (inputPath.startsWith('~/')) {
- result = path.join(cwd || '/home/user', inputPath.substring(2))
+ result = path.posix.join(cwd || '/home/user', inputPath.substring(2))
if (!cwd) {
logger.warn?.(
`Path starts with '~/' and cwd isn't set. The path '${inputPath}' will evaluate to '${result}', which may not be what you want.`,
@@ -37,7 +37,7 @@ export const resolvePath = (
}
if (!inputPath.startsWith('/') && cwd) {
- return path.join(cwd, inputPath)
+ return path.posix.join(cwd, inputPath)
}
return inputPath
diff --git a/packages/js-sdk/test/process.test.mjs b/packages/js-sdk/test/process.test.mjs
index a2233fcad..08f77f298 100644
--- a/packages/js-sdk/test/process.test.mjs
+++ b/packages/js-sdk/test/process.test.mjs
@@ -68,4 +68,4 @@ test('process send stdin', async () => {
// assert.equal(message.error, false)
await session.close()
-})
+}, 10000)
diff --git a/packages/js-sdk/test/runCode.test.mjs b/packages/js-sdk/test/runCode.test.mjs
index 831b4fedf..9a78f6888 100644
--- a/packages/js-sdk/test/runCode.test.mjs
+++ b/packages/js-sdk/test/runCode.test.mjs
@@ -13,7 +13,7 @@ raise Exception("err")
console.log('stderr', stderr)
expect(stdout.length).toEqual(50)
expect(stderr).toContain('Exception: err')
-})
+}, 10000)
test('run code using unsupported runtime', async () => {
await expect(() => runCode('Unsupported', 'print("hello")')).rejects.toThrowError(
diff --git a/packages/python-sdk/e2b/utils/filesystem.py b/packages/python-sdk/e2b/utils/filesystem.py
index a6ded651b..208a2f75d 100644
--- a/packages/python-sdk/e2b/utils/filesystem.py
+++ b/packages/python-sdk/e2b/utils/filesystem.py
@@ -1,28 +1,28 @@
-import os
import warnings
+from pathlib import PurePosixPath
from typing import Optional
def resolve_path(path: str, cwd: Optional[str] = None) -> str:
warning = f"Path starts with %()s and cwd isn't set. The path {path} will evaluate to `%()s`, which may not be what you want."
if path.startswith("./"):
- result = os.path.join(cwd or "/home/user", path)
+ result = PurePosixPath(cwd or "/home/user", path).as_posix()
if not cwd:
warnings.warn(warning.format("./", result))
return result
if path.startswith("../"):
- result = os.path.join(cwd or "/home/user", path)
+ result = PurePosixPath(cwd or "/home/user", path).as_posix()
if not cwd:
warnings.warn(warning.format("../", result))
return result
if path.startswith("~/"):
- result = os.path.join("/home/user", path[2:])
+ result = PurePosixPath("/home/user", path[2:]).as_posix()
warnings.warn(warning.format("~/", result))
return result
if not path.startswith("/") and cwd:
- return os.path.join(cwd, path)
+ return PurePosixPath(cwd, path).as_posix()
return path