diff --git a/.changeset/bash-cwd.md b/.changeset/bash-cwd.md new file mode 100644 index 00000000..99103155 --- /dev/null +++ b/.changeset/bash-cwd.md @@ -0,0 +1,5 @@ +--- +'@e2b/code-interpreter-template': patch +--- + +Apply cwd to bash kernel contexts (previously ignored, so `pwd` returned `/` regardless of the requested working directory) diff --git a/js/tests/cwd.test.ts b/js/tests/cwd.test.ts index b9a35ca3..14b671d4 100644 --- a/js/tests/cwd.test.ts +++ b/js/tests/cwd.test.ts @@ -40,3 +40,10 @@ sandboxTest.skipIf(isDebug)('cwd java', async ({ sandbox }) => { }) expect(result.results[0]?.text.trim()).toEqual('/home/user') }) + +sandboxTest.skipIf(isDebug)('cwd bash', async ({ sandbox }) => { + const result = await sandbox.runCode('pwd', { + language: 'bash', + }) + expect(result.logs.stdout.join().trim()).toEqual('/home/user') +}) diff --git a/python/tests/async/test_async_cwd.py b/python/tests/async/test_async_cwd.py index e03b3e68..1896d767 100644 --- a/python/tests/async/test_async_cwd.py +++ b/python/tests/async/test_async_cwd.py @@ -33,3 +33,9 @@ async def test_cwd_java(async_sandbox: AsyncSandbox): 'System.getProperty("user.dir")', language="java" ) assert result.results[0].text.strip() == "/home/user" + + +@pytest.mark.skip_debug() +async def test_cwd_bash(async_sandbox: AsyncSandbox): + result = await async_sandbox.run_code("pwd", language="bash") + assert "".join(result.logs.stdout).strip() == "/home/user" diff --git a/python/tests/sync/test_cwd.py b/python/tests/sync/test_cwd.py index 35f91a2b..b238f7e9 100644 --- a/python/tests/sync/test_cwd.py +++ b/python/tests/sync/test_cwd.py @@ -31,3 +31,9 @@ def test_cwd_r(sandbox: Sandbox): def test_cwd_java(sandbox: Sandbox): result = sandbox.run_code('System.getProperty("user.dir")', language="java") assert result.results[0].text.strip() == "/home/user" + + +@pytest.mark.skip_debug() +def test_cwd_bash(sandbox: Sandbox): + result = sandbox.run_code("pwd", language="bash") + assert "".join(result.logs.stdout).strip() == "/home/user" diff --git a/template/server/messaging.py b/template/server/messaging.py index 0db59af0..c51f8b21 100644 --- a/template/server/messaging.py +++ b/template/server/messaging.py @@ -304,6 +304,8 @@ async def change_current_directory( request = self._get_execute_request( message_id, f'System.setProperty("user.dir", "{path}");', True ) + elif language == "bash": + request = self._get_execute_request(message_id, f"cd '{path}'", True) else: return