Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bash-cwd.md
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions js/tests/cwd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
6 changes: 6 additions & 0 deletions python/tests/async/test_async_cwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions python/tests/sync/test_cwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions template/server/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading