From 8f692797f47af3c94d9d1c014646898c1bd2d68b Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Thu, 14 May 2026 19:38:03 +0200 Subject: [PATCH 1/2] Apply cwd to bash kernel contexts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The change_current_directory handler in the template server only had branches for python, javascript/typescript, r, and java — bash fell through to the no-op else, so a context created with a non-default cwd still returned `/` from `pwd`. Added a bash branch that sends `cd ` and added bash cwd tests across sync/async python and js suites. Co-Authored-By: Claude Opus 4.7 --- .changeset/bash-cwd.md | 5 +++++ js/tests/cwd.test.ts | 7 +++++++ python/tests/async/test_async_cwd.py | 6 ++++++ python/tests/sync/test_cwd.py | 6 ++++++ template/server/messaging.py | 2 ++ 5 files changed, 26 insertions(+) create mode 100644 .changeset/bash-cwd.md 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..651956a2 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 From 741632514bb400576a560453406b755d1df8826e Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Thu, 14 May 2026 19:44:12 +0200 Subject: [PATCH 2/2] Quote path in bash cd snippet Matches the quoting used in the js, r, and java branches so paths containing spaces or shell metacharacters cd to the intended directory. Co-Authored-By: Claude Opus 4.7 --- template/server/messaging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/server/messaging.py b/template/server/messaging.py index 651956a2..c51f8b21 100644 --- a/template/server/messaging.py +++ b/template/server/messaging.py @@ -305,7 +305,7 @@ async def change_current_directory( message_id, f'System.setProperty("user.dir", "{path}");', True ) elif language == "bash": - request = self._get_execute_request(message_id, f"cd {path}", True) + request = self._get_execute_request(message_id, f"cd '{path}'", True) else: return