Skip to content

armgit / E2B

Public Imported from GitHub
0

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

fix(js-sdk): return boolean from Sandbox.kill() instance method (#1426)

Mish Ushakovfeb2d452fa39
diff --git a/.changeset/itchy-camels-report.md b/.changeset/itchy-camels-report.md
new file mode 100644
index 000000000..a9d2af4fa
--- /dev/null
+++ b/.changeset/itchy-camels-report.md
@@ -0,0 +1,5 @@
+---
+"e2b": patch
+---
+
+Return `boolean` from the `Sandbox.kill()` instance method (`true` if the sandbox was killed, `false` if it was not found), matching the static `Sandbox.kill()` and the Python SDK.
diff --git a/packages/js-sdk/src/sandbox/index.ts b/packages/js-sdk/src/sandbox/index.ts
index 85790deb9..79d18b98b 100644
--- a/packages/js-sdk/src/sandbox/index.ts
+++ b/packages/js-sdk/src/sandbox/index.ts
@@ -507,14 +507,18 @@ export class Sandbox extends SandboxApi {
* Kill the sandbox.
*
* @param opts connection options.
+ *
+ * @returns `true` if the sandbox was killed, `false` if the sandbox was not found.
*/
- async kill(opts?: Pick<SandboxOpts, 'requestTimeoutMs' | 'signal'>) {
+ async kill(
+ opts?: Pick<SandboxOpts, 'requestTimeoutMs' | 'signal'>
+ ): Promise<boolean> {
if (this.connectionConfig.debug) {
// Skip killing the sandbox in debug mode
- return
+ return true
}
- await SandboxApi.kill(this.sandboxId, this.resolveApiOpts(opts))
+ return await SandboxApi.kill(this.sandboxId, this.resolveApiOpts(opts))
}
/**
diff --git a/packages/js-sdk/tests/sandbox/kill.test.ts b/packages/js-sdk/tests/sandbox/kill.test.ts
index be764b266..6cb9c698b 100644
--- a/packages/js-sdk/tests/sandbox/kill.test.ts
+++ b/packages/js-sdk/tests/sandbox/kill.test.ts
@@ -4,7 +4,8 @@ import { Sandbox } from '../../src'
import { sandboxTest, isDebug } from '../setup.js'
sandboxTest.skipIf(isDebug)('kill', async ({ sandbox, sandboxTestId }) => {
- await sandbox.kill()
+ const killed = await sandbox.kill()
+ expect(killed).toBe(true)
const paginator = Sandbox.list({
query: { state: ['running'], metadata: { sandboxTestId } },