Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix sandbox killing in tests
Tomas Valenta497bdc95d974
diff --git a/packages/js-sdk/tests/runtimes/browser/run.test.tsx b/packages/js-sdk/tests/runtimes/browser/run.test.tsxindex 293edf518..6686bb361 100644--- a/packages/js-sdk/tests/runtimes/browser/run.test.tsx+++ b/packages/js-sdk/tests/runtimes/browser/run.test.tsx@@ -11,10 +11,16 @@ function E2BTest() {useEffect(() => {const getText = async () => {const sandbox = await Sandbox.create()- await sandbox.commands.run('echo "Hello World" > hello.txt')- const content = await sandbox.files.read('hello.txt')- setText(content)++ try {+ await sandbox.commands.run('echo "Hello World" > hello.txt')+ const content = await sandbox.files.read('hello.txt')+ setText(content)+ } finally {+ await sandbox.kill()+ }}+getText()}, [])diff --git a/packages/js-sdk/tests/sandbox/commands/envVars.test.ts b/packages/js-sdk/tests/sandbox/commands/envVars.test.tsindex c94b5c712..148b0a4f5 100644--- a/packages/js-sdk/tests/sandbox/commands/envVars.test.ts+++ b/packages/js-sdk/tests/sandbox/commands/envVars.test.ts@@ -13,8 +13,12 @@ sandboxTest.skipIf(isDebug)('env vars', async ({ sandbox }) => {sandboxTest.skipIf(isDebug)('env vars on sandbox', async () => {const sandbox = await Sandbox.create({ envs: { FOO: 'bar' } })- const cmd = await sandbox.commands.run('echo "$FOO"')+ try {+ const cmd = await sandbox.commands.run('echo "$FOO"')- assert.equal(cmd.exitCode, 0)- assert.equal(cmd.stdout.trim(), 'bar')+ assert.equal(cmd.exitCode, 0)+ assert.equal(cmd.stdout.trim(), 'bar')+ } finally {+ await sandbox.kill()+ }})diff --git a/packages/python-sdk/tests/async/sandbox_async/commands/test_env_vars.py b/packages/python-sdk/tests/async/sandbox_async/commands/test_env_vars.pyindex b0d671428..e65b5d3c3 100644--- a/packages/python-sdk/tests/async/sandbox_async/commands/test_env_vars.py+++ b/packages/python-sdk/tests/async/sandbox_async/commands/test_env_vars.py@@ -10,8 +10,9 @@ async def test_command_envs(async_sandbox: AsyncSandbox):@pytest.mark.skip_debug()async def test_sandbox_envs(template: str):- sbx = await AsyncSandbox.create(template, envs={"FOO": "bar"})- cmd = await sbx.commands.run("echo $FOO")- assert cmd.stdout.strip() == "bar"-- await sbx.kill()+ try:+ sbx = await AsyncSandbox.create(template, envs={"FOO": "bar"})+ cmd = await sbx.commands.run("echo $FOO")+ assert cmd.stdout.strip() == "bar"+ finally:+ await sbx.kill()diff --git a/packages/python-sdk/tests/sync/sandbox_sync/commands/test_env_vars.py b/packages/python-sdk/tests/sync/sandbox_sync/commands/test_env_vars.pyindex e0d364c55..316274a14 100644--- a/packages/python-sdk/tests/sync/sandbox_sync/commands/test_env_vars.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/commands/test_env_vars.py@@ -11,7 +11,8 @@ def test_command_envs(sandbox: Sandbox):@pytest.mark.skip_debug()def test_sandbox_envs(template: str):sandbox = Sandbox(template, envs={"FOO": "bar"})- cmd = sandbox.commands.run("echo $FOO")- assert cmd.stdout.strip() == "bar"-- sandbox.kill()+ try:+ cmd = sandbox.commands.run("echo $FOO")+ assert cmd.stdout.strip() == "bar"+ finally:+ sandbox.kill()