Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
[WIP] Update error comments; [WIP] Prepare tests
Tomas Valenta7c98d3bd01de
diff --git a/packages/js-sdk/src/errors.ts b/packages/js-sdk/src/errors.tsindex d2d69eb48..64be65df0 100644--- a/packages/js-sdk/src/errors.ts+++ b/packages/js-sdk/src/errors.ts@@ -5,17 +5,29 @@ export function formatSandboxTimeoutError(message: string) {)}+/**+ * Thrown when a sandbox error occurs.+ *+ * Base class for all sandbox errors.+ */export class SandboxError extends Error {constructor(message: any) {super(message)this.name = 'SandboxError'}}-// [unknown] is sometimes caused by the sandbox timeout when the request is not processed-// [unavailable] is caused by sandbox timeout-// [canceled] is caused by exceeding request timeout-// [deadline_exceeded] is caused by exceeding the timeout (for process handlers, watch, etc)+/**+ * Thrown when a timeout error occurs.+ *+ * The [unavailable] error type is caused by sandbox timeout.+ *+ * The [canceled] error type is caused by exceeding request timeout.+ *+ * The [deadline_exceeded] error type is caused by exceeding the timeout for process, watch, etc.+ *+ * The [unknown] error type is sometimes caused by the sandbox timeout when the request is not processed correctly.+ */export class TimeoutError extends SandboxError {constructor(message: string) {super(message)@@ -23,6 +35,9 @@ export class TimeoutError extends SandboxError {}}+/**+ * Thrown when an invalid user is provided.+ */export class InvalidUserError extends SandboxError {constructor(message: string) {super(message)@@ -30,6 +45,9 @@ export class InvalidUserError extends SandboxError {}}+/**+ * Thrown when an invalid path is provided.+ */export class InvalidPathError extends SandboxError {constructor(message: string) {super(message)@@ -37,6 +55,9 @@ export class InvalidPathError extends SandboxError {}}+/**+ * Thrown when there is not enough disk space.+ */export class NotEnoughDiskSpaceError extends SandboxError {constructor(message: string) {super(message)@@ -44,6 +65,9 @@ export class NotEnoughDiskSpaceError extends SandboxError {}}+/**+ * Thrown when a resource is not found.+ */export class NotFoundError extends SandboxError {constructor(message: string) {super(message)@@ -51,9 +75,12 @@ export class NotFoundError extends SandboxError {}}+/**+ * Thrown when authentication fails.+ */export class AuthenticationError extends SandboxError {constructor(message: any) {super(message)this.name = 'AuthenticationError'}-}\ No newline at end of file+}diff --git a/packages/js-sdk/src/index.ts b/packages/js-sdk/src/index.tsindex 1a6b0ba97..7d2cb01ce 100644--- a/packages/js-sdk/src/index.ts+++ b/packages/js-sdk/src/index.ts@@ -44,6 +44,7 @@ export type {ProcessStartOpts,} from './sandbox/process'+export type { SandboxInfo } from './sandbox/sandboxApi'import { Sandbox } from './sandbox'export { Sandbox }export default Sandboxdiff --git a/packages/js-sdk/src/logs.ts b/packages/js-sdk/src/logs.tsindex 3b539e5b7..a08183dc2 100644--- a/packages/js-sdk/src/logs.ts+++ b/packages/js-sdk/src/logs.ts@@ -1,6 +1,10 @@import type { Interceptor } from '@connectrpc/connect'import type { Middleware } from 'openapi-fetch'+/**+ * Logger interface compatible with `console` that can be used in places that accept `Logger`+ * to log messages into the console.+ */export interface Logger {debug?: (...args: any[]) => voidinfo?: (...args: any[]) => voiddiff --git a/packages/js-sdk/src/sandbox/sandboxApi.ts b/packages/js-sdk/src/sandbox/sandboxApi.tsindex 6754d7ddf..f746a1b02 100644--- a/packages/js-sdk/src/sandbox/sandboxApi.ts+++ b/packages/js-sdk/src/sandbox/sandboxApi.ts@@ -2,11 +2,33 @@ import { ApiClient, handleApiError } from '../api'import { ConnectionConfig, ConnectionOpts } from '../connectionConfig'-export interface RunningSandbox {+/**+ * Information about a sandbox.+ */+export interface SandboxInfo {+ /**+ * Sandbox ID.+ */sandboxID: string++ /**+ * Template ID.+ */templateID: string++ /**+ * Sandbox name.+ */name?: string++ /**+ * Saved sandbox metadata.+ */metadata?: Record<string, string>++ /**+ * Sandbox start time.+ */startedAt: Date}@@ -34,7 +56,7 @@ export class SandboxApi {}}- static async list(opts?: ConnectionOpts): Promise<RunningSandbox[]> {+ static async list(opts?: ConnectionOpts): Promise<SandboxInfo[]> {const config = new ConnectionConfig(opts)const client = new ApiClient(config)diff --git a/packages/js-sdk/test/_smoke.test.mjs b/packages/js-sdk/test/_smoke.test.mjsdeleted file mode 100644index 0f7f0c058..000000000--- a/packages/js-sdk/test/_smoke.test.mjs+++ /dev/null@@ -1,14 +0,0 @@-import { Sandbox } from '../src'-import { expect, test } from 'vitest'-import { id } from './setup.mjs'--// Smoke test = quick, high-level, basic functionality test-test.skip('Smoke test', async () => {- const sandbox = await Sandbox.create({ id })- await sandbox.filesystem.makeDir('/test/new')-- const ls = await sandbox.filesystem.list('/test')- expect(ls.map(x => x.name)).toEqual(['new'])-- await sandbox.close()-})diff --git a/packages/js-sdk/test/api/kill.test.mjs b/packages/js-sdk/test/api/kill.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/api/list.test.mjs b/packages/js-sdk/test/api/list.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/assets/video.webm b/packages/js-sdk/test/assets/video.webmdeleted file mode 100644index 77f488a57..000000000Binary files a/packages/js-sdk/test/assets/video.webm and /dev/null differdiff --git a/packages/js-sdk/test/cwd.test.mjs b/packages/js-sdk/test/cwd.test.mjsdeleted file mode 100644index 758481a05..000000000--- a/packages/js-sdk/test/cwd.test.mjs+++ /dev/null@@ -1,110 +0,0 @@-import { Sandbox } from '../src'-import { expect, test, vi } from 'vitest'--import { id } from './setup.mjs'-import { CurrentWorkingDirectoryDoesntExistError } from '../src/error'--test('custom cwd', async () => {- const sandbox = await Sandbox.create({- id,- cwd: '/code/app'- })-- // change dir to /home/user- sandbox.cwd = '/home/user'-- // process respects cwd- {- const proc = await sandbox.process.start({ cmd: 'pwd' })- await proc.finished- const out = proc.output.stdout- expect(out).toEqual('/home/user')- }-- // filesystem respects cwd- {- await sandbox.filesystem.write('hello.txt', 'Hello VM!')- const proc = await sandbox.process.start({ cmd: 'cat /home/user/hello.txt' })- await proc.finished- const out = proc.output.stdout- expect(out).toEqual('Hello VM!')- }-- // call cd in process- {- const proc = await sandbox.process.start({ cmd: 'cd /code' })- await proc.finished- }-- // process doesn't respect cd- {- const proc = await sandbox.process.start({ cmd: 'pwd' })- await proc.finished- const out = proc.output.stdout- expect(out).toEqual('/home/user')- }- await sandbox.close()-})--test('test_process_cwd', async () => {- const sandbox = await Sandbox.create({ id, cwd: '/code/app' })- const proc = await sandbox.process.start({ cmd: 'pwd' })- await proc.wait()- expect(proc.output.stdout).toEqual('/code/app')- await sandbox.close()-})--test('test_filesystem_cwd', async () => {- const sandbox = await Sandbox.create({ id, cwd: '/code/app' })-- await sandbox.filesystem.write('hello.txt', 'Hello VM!')- const proc = await sandbox.process.start({ cmd: 'cat /code/app/hello.txt' })-- await proc.wait()- expect(proc.output.stdout).toEqual('Hello VM!')- await sandbox.close()-})--test('test_initial_cwd_with_tilde', async () => {- const sandbox = await Sandbox.create({ id, cwd: '~/code/' })- const proc = await sandbox.process.start({ cmd: 'pwd' })- await proc.wait()- expect(proc.output.stdout).toEqual('/home/user/code')- await sandbox.close()-})--test('test_relative_paths', async () => {- const sandbox = await Sandbox.create({ id, cwd: '/home/user' })- await sandbox.filesystem.makeDir('./code')- await sandbox.filesystem.write('./code/hello.txt', 'Hello Vasek!')- const proc = await sandbox.process.start({ cmd: 'cat /home/user/code/hello.txt' })- await proc.wait()- expect(proc.output.stdout).toEqual('Hello Vasek!')-- await sandbox.filesystem.write('../../hello.txt', 'Hello Tom!')- const proc2 = await sandbox.process.start({ cmd: 'cat /hello.txt' })- await proc2.wait()- expect(proc2.output.stdout).toEqual('Hello Tom!')-- await sandbox.close()-})--test('test_warnings', async () => {- const sandbox = await Sandbox.create({- id,- logger: { warn: vi.spyOn(console, 'warn') }- })- await sandbox.filesystem.write('./hello.txt', 'Hello Vasek!')- expect(console.warn).toHaveBeenCalledTimes(1)- await sandbox.filesystem.write('../hello.txt', 'Hello Vasek!')- expect(console.warn).toHaveBeenCalledTimes(2)- await sandbox.filesystem.write('~/hello.txt', 'Hello Vasek!')- expect(console.warn).toHaveBeenCalledTimes(3)- await sandbox.close()-})--test('test_non_existing_cwd', async () => {- const sandbox = await Sandbox.create({ id })- await expect(sandbox.process.start({ cmd: 'pwd', cwd: '/this/does/not/exist' })).rejects.toThrow(CurrentWorkingDirectoryDoesntExistError)- await sandbox.close()-})diff --git a/packages/js-sdk/test/envVars.test.mjs b/packages/js-sdk/test/envVars.test.mjsdeleted file mode 100644index a1cfed511..000000000--- a/packages/js-sdk/test/envVars.test.mjs+++ /dev/null@@ -1,55 +0,0 @@-import { Sandbox } from '../src'-import { expect, test } from 'vitest'--import { id } from './setup.mjs'--test('test_env_vars', async () => {- const sandbox = await Sandbox.create({ id })-- const process = await sandbox.process.start({- cmd: 'echo $FOO',- envVars: { FOO: 'BAR' }- })- await process.wait()- const output = process.output.stdout- expect(output).toEqual('BAR')-- await sandbox.close()-})--test('test_profile_env_vars', async () => {- const sandbox = await Sandbox.create({ id })-- await sandbox.filesystem.write('/home/user/.profile', 'export FOO=BAR')- const process = await sandbox.process.start({ cmd: 'echo $FOO' })- await process.wait()- const output = process.output.stdout- expect(output).toEqual('BAR')-- await sandbox.close()-})--test('test_default_env_vars', async () => {- const sandbox = await Sandbox.create({ id, envVars: { FOO: 'BAR' } })-- const process = await sandbox.process.start({ cmd: 'echo $FOO' })- await process.wait()- const output = process.output.stdout- expect(output).toEqual('BAR')-- await sandbox.close()-})--test('test_overriding_env_vars', async () => {- const sandbox = await Sandbox.create({ id, envVars: { FOO: 'BAR' } })-- const process = await sandbox.process.start({- cmd: 'echo $FOO',- envVars: { FOO: 'QUX' }- })- await process.wait()- const output = process.output.stdout- expect(output).toEqual('QUX')-- await sandbox.close()-})diff --git a/packages/js-sdk/test/fileUploadDownload.test.mjs b/packages/js-sdk/test/fileUploadDownload.test.mjsdeleted file mode 100644index a359fda9b..000000000--- a/packages/js-sdk/test/fileUploadDownload.test.mjs+++ /dev/null@@ -1,22 +0,0 @@-import { Sandbox } from '../src'-import { expect, test } from 'vitest'-import * as fs from 'node:fs'-import * as path from 'node:path'--import { id } from './setup.mjs'--test('upload and download file', async () => {- const sandbox = await Sandbox.create({ id })-- const localFile = fs.readFileSync(path.join(__dirname, '/assets/video.webm'))-- const uploadedFilePath = await sandbox.uploadFile(localFile, 'video.webm')-- const ls = await sandbox.filesystem.list('/home/user')- expect(ls.map(x => x.name)).contains('video.webm')-- const downloadedFile = await sandbox.downloadFile(uploadedFilePath, 'buffer')- expect(localFile).toEqual(downloadedFile)-- await sandbox.close()-})diff --git a/packages/js-sdk/test/filesystem.test.mjs b/packages/js-sdk/test/filesystem.test.mjsdeleted file mode 100644index 2546fb9dd..000000000--- a/packages/js-sdk/test/filesystem.test.mjs+++ /dev/null@@ -1,81 +0,0 @@-import { Sandbox } from '../src'-import { expect, test } from 'vitest'-import * as fs from 'node:fs'-import * as path from 'node:path'-import { id } from './setup.mjs'--test('list files', async () => {- const sandbox = await Sandbox.create({ id })- await sandbox.filesystem.makeDir('/test/new')-- const ls = await sandbox.filesystem.list('/test')- expect(ls.map(x => x.name)).toEqual(['new'])-- await sandbox.close()-})--test('create file', async () => {- const sandbox = await Sandbox.create({ id })- await sandbox.filesystem.makeDir('/test')- await sandbox.filesystem.write('/test/test.txt', 'Hello World!')-- const ls = await sandbox.filesystem.list('/test')- expect(ls.map(x => x.name)).toEqual(['test.txt'])-- await sandbox.close()-})--test('read and write', async () => {- const sandbox = await Sandbox.create({ id })-- // String- await sandbox.filesystem.write('/tmp/test.txt', 'Hello World!')- const content = await sandbox.filesystem.read('/tmp/test.txt')- expect(content).toEqual('Hello World!')-- // Binary file- const binaryFile = fs.readFileSync(path.join(__dirname, '/assets/video.webm'))- await sandbox.filesystem.writeBytes('/tmp/video.webm', binaryFile)- const binaryContent = await sandbox.filesystem.readBytes('/tmp/video.webm')- expect(binaryContent).toEqual(binaryFile)-- await sandbox.close()-})--test('list delete files', async () => {- const sandbox = await Sandbox.create({ id })- await sandbox.filesystem.makeDir('/test/new')-- let ls = await sandbox.filesystem.list('/test')- expect(ls.map(x => x.name)).toEqual(['new'])-- await sandbox.filesystem.remove('/test/new')-- ls = await sandbox.filesystem.list('/test')- expect(ls.map(x => x.name)).toEqual([])-- await sandbox.close()-})--test('watch dir', async () => {- const sandbox = await Sandbox.create({ id })- await sandbox.filesystem.write('/tmp/test.txt', 'Hello')-- const watcher = sandbox.filesystem.watchDir('/tmp')-- const events = []- watcher.addEventListener(ev => events.push(ev))-- await watcher.start()- await sandbox.filesystem.write('/tmp/test.txt', 'World!')- await new Promise(r => setTimeout(r, 2500))- await watcher.stop()-- expect(events.length).toBeGreaterThanOrEqual(1)-- const event = events[0]- expect(event['operation']).toEqual('Write')- expect(event['path']).toEqual('/tmp/test.txt')-- await sandbox.close()-})diff --git a/packages/js-sdk/test/killSandbox.test.mjs b/packages/js-sdk/test/killSandbox.test.mjsdeleted file mode 100644index e66a16647..000000000--- a/packages/js-sdk/test/killSandbox.test.mjs+++ /dev/null@@ -1,10 +0,0 @@-import { expect, test } from 'vitest'-import { Sandbox } from '../src'--test('kill running sandbox', async () => {- const sandbox = await Sandbox.create()- await Sandbox.kill(sandbox.id)- const list = await Sandbox.list()- expect(list.map((s) => s.sandboxID)).not.toContain(sandbox.id)- await sandbox.close()-})diff --git a/packages/js-sdk/test/listRunningSandboxes.test.mjs b/packages/js-sdk/test/listRunningSandboxes.test.mjsdeleted file mode 100644index 97941a2d3..000000000--- a/packages/js-sdk/test/listRunningSandboxes.test.mjs+++ /dev/null@@ -1,22 +0,0 @@-import { expect, test } from 'vitest'-import { Sandbox } from '../src'--test('list running sandboxes', async () => {- const sandboxPromises = []- for (let i = 0; i < 3; i++) {- sandboxPromises.push(Sandbox.create({- id: 'base',- apiKey: process.env.E2B_API_KEY,- metadata: { n: `js${i}` }- }))- }- const sandboxes = await Promise.all(sandboxPromises)-- const running = (await Sandbox.list()).filter(s => s.metadata?.n?.startsWith('js'))- expect(running.length).toEqual(3)- expect(new Set(running.map(s => s.metadata['n']))).toEqual(new Set(['js0', 'js1', 'js2']))-- for (const sandbox of sandboxes) {- await sandbox.close()- }-})diff --git a/packages/js-sdk/test/logging.test.mjs b/packages/js-sdk/test/logging.test.mjsdeleted file mode 100644index aeea4332a..000000000--- a/packages/js-sdk/test/logging.test.mjs+++ /dev/null@@ -1,65 +0,0 @@-import { Sandbox } from '../src'-import { expect, test, vi } from 'vitest'--import { id } from './setup.mjs'--test.skip('no logs in console during very basic scenario', async () => {- const consoleSpy = {- debug: vi.spyOn(console, 'debug'),- info: vi.spyOn(console, 'info'),- warn: vi.spyOn(console, 'warn'),- error: vi.spyOn(console, 'error')- }-- const sandbox = await Sandbox.create({ id })- await sandbox.filesystem.write('test.txt', 'Hello World')- await sandbox.close()-- expect(consoleSpy.debug).toHaveBeenCalledTimes(0)- expect(consoleSpy.info).toHaveBeenCalledTimes(2)- expect(consoleSpy.error).toHaveBeenCalledTimes(0)-})--// TODO: Re-enable https://e2b-team.slack.com/archives/C05AGT4UFMJ/p1694697558738799?thread_ts=1694697479.308769&cid=C05AGT4UFMJ-test.skip('warn logs in console during convoluted scenario', async () => {- const consoleSpy = {- debug: vi.spyOn(console, 'debug'),- info: vi.spyOn(console, 'info'),- warn: vi.spyOn(console, 'warn'),- error: vi.spyOn(console, 'error')- }-- const sandbox = await Sandbox.create({ id })- await sandbox.close() // Note that we are intentionally closing and then trying to write- const warnsAmount = consoleSpy.warn.mock.calls.length-- // void to explicitly not awaiting, we wanna check if logging is happening correctly during retries- void sandbox.filesystem.read('/etc/hosts') // this should trigger retries- setTimeout(() => {- expect(consoleSpy.warn.mock.calls.length).toBeGreaterThan(warnsAmount) // should have logged a warning- }, 2000) // wait for some retries to occur-})--test.skip('verbose & info logs in console when opted-in', async () => {- const consoleSpy = {- info: vi.spyOn(console, 'info'),- warn: vi.spyOn(console, 'warn'),- error: vi.spyOn(console, 'error')- }-- const logger = {- info: console.info,- warn: console.warn,- error: console.error- }-- const sandbox = await Sandbox.create({- id,- logger- })- await sandbox.filesystem.write('test.txt', 'Hello World')- await sandbox.close()-- expect(consoleSpy.info).toHaveBeenCalled()- expect(consoleSpy.error).toHaveBeenCalledTimes(0)-})diff --git a/packages/js-sdk/test/performance.mjs b/packages/js-sdk/test/performance.mjsdeleted file mode 100644index 948143b0b..000000000--- a/packages/js-sdk/test/performance.mjs+++ /dev/null@@ -1,111 +0,0 @@-import { writeFileSync } from 'fs'--import { Sandbox } from '../dist/index.js'--const reportSummaryFile = process.env.SUMMARY_FILE || './test.md'--const codeSnippetIDs = ['5udkAFHBVrGz']-const samplePerID = 15-const upperBoundary = 1000 // 1s--async function spinSandbox(id) {- console.log('Creating sandbox...')- let sandbox- try {- const startTime = performance.now()- sandbox = new Sandbox({- id- // debug: true,- })- sandbox.open()-- const endTime = performance.now()- return endTime - startTime- } catch (e) {- console.error(`Measuring ${id} failed`, e)- } finally {- ;(async () => {- try {- // await sandbox?.close()- } catch (e) {- // Do nothing- }- })()- }-- throw new Error('**Measurement failed**')-}--function createReport(data, time) {- let template = `# E2B SDK - Sandbox Performance--*${time}*--## Results--| Test | Samples | Result |-| ------------- | ------------- | ------------- |`-- const createRow = (key, value) => {- template = template + `\n| ${key} | ${value.size} | ${value.result} |`- }-- Object.entries(data).forEach(e => createRow(e[0], e[1]))-- return template-}--function writeMeasurements(data) {- const time = new Date(Date.now())-- const report = createReport(data, time)- writeFileSync(reportSummaryFile, report)-}--async function sample(id, size) {- let totalTime = 0- const entryName = `Public sandbox (${id})`-- try {- for (let i = 0; i < size; i++) {- const timeToSandbox = await spinSandbox(id)- totalTime += timeToSandbox- }-- const averageTime = Math.round(totalTime / size)-- return {- [entryName]: {- result: `${averageTime}ms ${averageTime < upperBoundary ? ':heavy_check_mark:' : ':x:'- }`,- size- }- }- } catch (e) {- return {- [entryName]: {- size,- result: e.message- }- }- }-}--async function main() {- let entries = {}-- for (const id of codeSnippetIDs) {- const entry = await sample(id, samplePerID)- entries = { ...entries, ...entry }- }-- // for (const id of codeSnippetIDs) {- // // We do only one sample of persistent sandbox because otherview we would get reconnected to the same sandbox- // const entry = await sample(id, 1, true)- // entries = { ...entries, ...entry }- // }-- writeMeasurements(entries)-}--main()diff --git a/packages/js-sdk/test/process.test.mjs b/packages/js-sdk/test/process.test.mjsdeleted file mode 100644index 33748ca6d..000000000--- a/packages/js-sdk/test/process.test.mjs+++ /dev/null@@ -1,139 +0,0 @@-import { Sandbox } from '../src'-import { expect, test, vi } from 'vitest'--import { id } from './setup.mjs'--test('process on stdout/stderr', async () => {- const sandbox = await Sandbox.create({ id })-- const stdout = []- const stderr = []-- const process = await sandbox.process.start({- cmd: 'pwd',- onStdout: data => stdout.push(data),- onStderr: data => stderr.push(data),- cwd: '/tmp'- })-- const output = await process.finished-- expect(output.error).toEqual(false)- expect(output.stdout).toEqual('/tmp')- expect(output.stderr).toEqual('')- expect(stdout.map(message => message.line)).toEqual(['/tmp'])- expect(stderr).toEqual([])- expect(process.output.exitCode).toEqual(0)- await sandbox.close()-})--test('process expected stdout', async () => {- // TODO: Implement this once we fix envd stdout/stderr race condition-})--test('process expected stderr', async () => {- // TODO: Implement this once we fix envd stdout/stderr race condition-})--test('process on exit', async () => {- const sandbox = await Sandbox.create({ id })-- const onExit = vi.fn(() => {- })-- const process = await sandbox.process.start({- cmd: 'pwd',- onExit- })-- await process.wait()- expect(onExit).toHaveBeenCalled()-- await sandbox.close()-})--test('process send stdin', async () => {- const sandbox = await Sandbox.create({ id })-- const process = await sandbox.process.start({- cmd: 'read -r line; echo "$line"',- cwd: '/code'- })- await process.sendStdin('ping\n')- await process.wait()-- expect(process.output.stdout).toEqual('ping')- // TODO: Parity with Python SDK- // expect(process.output.messages.length).toEqual(1)- // const message = process.output_messages[0]- // assert.equal(message.line, "ping")- // assert.equal(message.error, false)-- await sandbox.close()-}, 10000)--test('test default on exit', async () => {- const onExit = vi.fn(() => {- })-- const sandbox = await Sandbox.create({ id, onExit })- const processOverride = await sandbox.process.start({- cmd: 'pwd',- onExit: console.log- })- await processOverride.finished- expect(onExit).not.toHaveBeenCalled()-- const process = await sandbox.process.start({- cmd: 'pwd'- })-- await process.wait()- expect(onExit).toHaveBeenCalled()-- await sandbox.close()-})--test('test default on stdout/stderr', async () => {- const onStdout = vi.fn(() => {- })- const onStderr = vi.fn(() => {- })-- const sandbox = await Sandbox.create({ id, onStdout, onStderr })-- const processOverride = await sandbox.process.start({- cmd: 'node -e "console.log(\'Hello\'); throw new Error(\'Ooopsie -_-\')"',- onStdout: () => {- },- onStderr: () => {- }- })-- await processOverride.wait()- expect(onStdout).not.toHaveBeenCalled()- expect(onStderr).not.toHaveBeenCalled()-- const process = await sandbox.process.start({- cmd: 'node -e "console.log(\'Hello\'); throw new Error(\'Ooopsie -_-\')"'- })-- await process.wait()- expect(onStdout).toHaveBeenCalledOnce()- expect(onStderr).toHaveBeenCalled()- expect(process.output.exitCode).toEqual(1)-- await sandbox.close()-}, 10000)----test('test process start and wait', async () => {- const sandbox = await Sandbox.create(id)-- const output = await sandbox.process.startAndWait('node -e "console.log(\'Hello\');"')-- expect(output.exitCode).toEqual(0)-- await sandbox.close()-})diff --git a/packages/js-sdk/test/sandbox/commands/connect.test.mjs b/packages/js-sdk/test/sandbox/commands/connect.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/commands/kill.test.mjs b/packages/js-sdk/test/sandbox/commands/kill.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/commands/list.test.mjs b/packages/js-sdk/test/sandbox/commands/list.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/commands/run.test.mjs b/packages/js-sdk/test/sandbox/commands/run.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/commands/sendStdin.test.mjs b/packages/js-sdk/test/sandbox/commands/sendStdin.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/connect.test.mjs b/packages/js-sdk/test/sandbox/connect.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/create.test.mjs b/packages/js-sdk/test/sandbox/create.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/files/exists.test.mjs b/packages/js-sdk/test/sandbox/files/exists.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/files/list.test.mjs b/packages/js-sdk/test/sandbox/files/list.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/files/makeDir.test.mjs b/packages/js-sdk/test/sandbox/files/makeDir.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/files/read.test.mjs b/packages/js-sdk/test/sandbox/files/read.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/files/remove.test.mjs b/packages/js-sdk/test/sandbox/files/remove.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/files/rename.test.mjs b/packages/js-sdk/test/sandbox/files/rename.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/files/watch.test.mjs b/packages/js-sdk/test/sandbox/files/watch.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/files/write.test.mjs b/packages/js-sdk/test/sandbox/files/write.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/pty/create.test.mjs b/packages/js-sdk/test/sandbox/pty/create.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/pty/resize.test.mjs b/packages/js-sdk/test/sandbox/pty/resize.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/pty/streamInput.test.mjs b/packages/js-sdk/test/sandbox/pty/streamInput.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/sandbox/timeout.test.mjs b/packages/js-sdk/test/sandbox/timeout.test.mjsnew file mode 100644index 000000000..e69de29bbdiff --git a/packages/js-sdk/test/session.test.mjs b/packages/js-sdk/test/session.test.mjsdeleted file mode 100644index 0c9b6f500..000000000--- a/packages/js-sdk/test/session.test.mjs+++ /dev/null@@ -1,16 +0,0 @@-import { Sandbox } from '../src'-import { test } from 'vitest'--import { id } from './setup.mjs'--test('create sandbox', async () => {- const sandbox = await Sandbox.create({ id })- await sandbox.close()-})--test('create multiple sandbox', async () => {- const sandbox = await Sandbox.create({ id })- const sandbox2 = await Sandbox.create({ id })- await sandbox.close()- await sandbox2.close()-})diff --git a/packages/js-sdk/test/timeout.test.mjs b/packages/js-sdk/test/timeout.test.mjsdeleted file mode 100644index d4bbca7d4..000000000--- a/packages/js-sdk/test/timeout.test.mjs+++ /dev/null@@ -1,70 +0,0 @@-import { expect, test } from 'vitest'--import { Sandbox } from '../src'-import { TimeoutError } from '../src/error.ts'--import { id } from './setup.mjs'--// TODO: Make it work on CI and re-enable!-test.skip('timeout sandbox', async () => {- await expect(Sandbox.create({ id, timeout: 10 })).rejects.toThrow()-})--// TODO: Make it work on CI and re-enable!-test.skip('dont timeout sandbox', async () => {- const sandbox = await Sandbox.create({- id,- timeout: 10000- })- await sandbox.close()-})--// TODO: Make it work on CI and re-enable!-test.skip('timeout filesystem', async () => {- const sandbox = await Sandbox.create({ id })- await expect(- sandbox.filesystem.write('/home/test.txt', 'Hello World', { timeout: 10 })- ).rejects.toThrow(TimeoutError)- await expect(- sandbox.filesystem.read('/home/test.txt', { timeout: 10 })- ).rejects.toThrow(TimeoutError)- await expect(sandbox.filesystem.list('/home', { timeout: 10 })).rejects.toThrow(- TimeoutError- )- await expect(- sandbox.filesystem.makeDir('/home/test/', { timeout: 10 })- ).rejects.toThrow(TimeoutError)- await sandbox.filesystem.write('/home/test.txt', 'Hello World')- await expect(- sandbox.filesystem.remove('/home/test.txt', { timeout: 10 })- ).rejects.toThrow(TimeoutError)-})--// TODO: Make it work on CI and re-enable!-test.skip('timeout process', async () => {- const sandbox = await Sandbox.create({ id: 'Nodejs' })- await expect(- sandbox.process.start({ cmd: 'node -e \'setTimeout(() => {}, 10000)\'', timeout: 10 })- ).rejects.toThrow(TimeoutError)- const process = await sandbox.process.start({- cmd: 'while true; do echo \'Hello World\'; sleep 1; done'- })- await expect(process.sendStdin('Hello World', { timeout: 10 })).rejects.toThrow(- TimeoutError- )-})--// TODO: Waiting for https://github.com/vitest-dev/vitest/issues/3119-test.skip('timeout longer than cmd should not leak', () =>- new Promise(async resolve => {- const sandbox = await Sandbox.create({ id: 'Nodejs' })- const proc = await sandbox.process.start({- cmd: 'node -e \'setTimeout(() => {}, 1000)\'', // should take around 1 second- onExit: () => {- // TODO: Verify that process finished after successful cmd, and not after timeout- resolve()- },- timeout: 10_000 // but we give it 10 seconds- })- await proc.finished- }))diff --git a/packages/python-sdk/e2b/__init__.py b/packages/python-sdk/e2b/__init__.pyindex 5ec902b31..04a949d99 100644--- a/packages/python-sdk/e2b/__init__.py+++ b/packages/python-sdk/e2b/__init__.py@@ -16,6 +16,7 @@ from .exceptions import (NotEnoughDiskSpaceException,AuthenticationException,)+from .sandbox.sandbox_api import SandboxInfofrom .sandbox.main import Sandboxfrom .sandbox.process.process_handle import (ProcessHandle,diff --git a/packages/python-sdk/e2b/exceptions.py b/packages/python-sdk/e2b/exceptions.pyindex c9cd30670..8eab4383c 100644--- a/packages/python-sdk/e2b/exceptions.py+++ b/packages/python-sdk/e2b/exceptions.py@@ -5,32 +5,63 @@ def format_sandbox_timeout_exception(message: str):class SandboxException(Exception):+ """+ Raised when a sandbox exception occurs.++ Base class for all sandbox errors.+ """+pass-# [unknown] is sometimes caused by the sandbox timeout when the request is not processed-# [unavailable] is caused by sandbox timeout-# [canceled] is caused by exceeding request timeout-# [deadline_exceeded] is caused by exceeding the timeout (for process handlers, watch, etc)class TimeoutException(SandboxException):+ """+ Raised when a timeout occurs.++ The [unavailable] exception type is caused by sandbox timeout.\n+ The [canceled] exception type is caused by exceeding request timeout.\n+ The [deadline_exceeded] exception type is caused by exceeding the timeout for process, watch, etc.\n+ The [unknown] exception type is sometimes caused by the sandbox timeout when the request is not processed correctly.\n+ """+passclass NotEnoughDiskSpaceException(SandboxException):+ """+ Raised when there is not enough disk space.+ """+passclass NotFoundException(SandboxException):+ """+ Raised when a resource is not found.+ """+passclass InvalidPathException(SandboxException):+ """+ Raised when an invalid path is provided.+ """+passclass InvalidUserException(SandboxException):+ """+ Raised when an invalid user is provided.+ """+passclass AuthenticationException(SandboxException):+ """+ Raised when authentication fails.+ """+passdiff --git a/packages/python-sdk/e2b/sandbox/sandbox_api.py b/packages/python-sdk/e2b/sandbox/sandbox_api.pyindex 1a7fda3bf..74db7addf 100644--- a/packages/python-sdk/e2b/sandbox/sandbox_api.py+++ b/packages/python-sdk/e2b/sandbox/sandbox_api.py@@ -8,12 +8,19 @@ from e2b.api import handle_api_exception@dataclass-class RunningSandbox:+class SandboxInfo:+ """Information about a sandbox."""+sandbox_id: str+ """Sandbox ID."""template_id: str+ """Template ID."""name: Optional[str]+ """Sandbox name."""metadata: Optional[Dict[str, str]]+ """Saved sandbox metadata."""started_at: datetime+ """Sandbox start time."""class SandboxApi:@@ -23,7 +30,7 @@ class SandboxApi:domain: Optional[str] = None,debug: Optional[bool] = None,request_timeout: Optional[float] = None,- ) -> List[RunningSandbox]:+ ) -> List[SandboxInfo]:config = ConnectionConfig(api_key=api_key,domain=domain,@@ -34,7 +41,7 @@ class SandboxApi:with ApiClient(config) as api_client:try:return [- RunningSandbox(+ SandboxInfo(sandbox_id=SandboxApi._get_sandbox_id(sandbox.sandbox_id,sandbox.client_id,diff --git a/packages/python-sdk/tests/api/test_kill.py b/packages/python-sdk/tests/api/test_kill.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/api/test_list.py b/packages/python-sdk/tests/api/test_list.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/assets/video.webm b/packages/python-sdk/tests/assets/video.webmdeleted file mode 100644index 77f488a57..000000000Binary files a/packages/python-sdk/tests/assets/video.webm and /dev/null differdiff --git a/packages/python-sdk/tests/infra/test_homedir.py b/packages/python-sdk/tests/infra/test_homedir.pydeleted file mode 100644index b9b204add..000000000--- a/packages/python-sdk/tests/infra/test_homedir.py+++ /dev/null@@ -1,11 +0,0 @@-from e2b import Sandbox---def test_homedir():- sandbox = Sandbox()-- process = sandbox.process.start("echo $HOME")- process.wait()- output = process.stdout- assert output == "/home/user"- sandbox.close()diff --git a/packages/python-sdk/tests/infra/test_install_package.py b/packages/python-sdk/tests/infra/test_install_package.pydeleted file mode 100644index 7b41796b4..000000000--- a/packages/python-sdk/tests/infra/test_install_package.py+++ /dev/null@@ -1,14 +0,0 @@-from e2b import Sandbox---def test_python_package():- sandbox = Sandbox()-- process = sandbox.process.start("pip install pip-install-test")- process.wait()-- process = sandbox.process.start('python -c "import pip_install_test"')- process.wait()- output = process.stdout- assert "Good job!" in output- sandbox.close()diff --git a/packages/python-sdk/tests/infra/test_sudo.py b/packages/python-sdk/tests/infra/test_sudo.pydeleted file mode 100644index 17ccaded4..000000000--- a/packages/python-sdk/tests/infra/test_sudo.py+++ /dev/null@@ -1,11 +0,0 @@-from e2b import Sandbox---def test_sudo():- sandbox = Sandbox()-- process = sandbox.process.start("sudo echo test")- process.wait()- output = process.stdout- assert output == "test"- sandbox.close()diff --git a/packages/python-sdk/tests/sandbox/commands/test_connect.py b/packages/python-sdk/tests/sandbox/commands/test_connect.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/commands/test_kill.py b/packages/python-sdk/tests/sandbox/commands/test_kill.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/commands/test_list.py b/packages/python-sdk/tests/sandbox/commands/test_list.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/commands/test_run.py b/packages/python-sdk/tests/sandbox/commands/test_run.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/commands/test_send_stdin.py b/packages/python-sdk/tests/sandbox/commands/test_send_stdin.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/files/test_exists.py b/packages/python-sdk/tests/sandbox/files/test_exists.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/files/test_list.py b/packages/python-sdk/tests/sandbox/files/test_list.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/files/test_make_dir.py b/packages/python-sdk/tests/sandbox/files/test_make_dir.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/files/test_read.py b/packages/python-sdk/tests/sandbox/files/test_read.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/files/test_remove.py b/packages/python-sdk/tests/sandbox/files/test_remove.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/files/test_rename.py b/packages/python-sdk/tests/sandbox/files/test_rename.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/files/test_watch.py b/packages/python-sdk/tests/sandbox/files/test_watch.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/files/test_write.py b/packages/python-sdk/tests/sandbox/files/test_write.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/test_connect.py b/packages/python-sdk/tests/sandbox/test_connect.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/test_create.py b/packages/python-sdk/tests/sandbox/test_create.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/sandbox/test_timeout.py b/packages/python-sdk/tests/sandbox/test_timeout.pynew file mode 100644index 000000000..e69de29bbdiff --git a/packages/python-sdk/tests/test_cwd.py b/packages/python-sdk/tests/test_cwd.pydeleted file mode 100644index 6d4445bb7..000000000--- a/packages/python-sdk/tests/test_cwd.py+++ /dev/null@@ -1,93 +0,0 @@-import pytest-from e2b import CurrentWorkingDirectoryDoesntExistException, Sandbox---def test_process_cwd():- sandbox = Sandbox(cwd="/code/app")-- proc = sandbox.process.start("pwd")- output = proc.wait()- assert output.stdout == "/code/app"- sandbox.close()---def test_filesystem_cwd():- sandbox = Sandbox(cwd="/code/app")-- sandbox.filesystem.write("hello.txt", "Hello VM!")- proc = sandbox.process.start("cat /code/app/hello.txt")- output = proc.wait()- assert output.stdout == "Hello VM!"-- sandbox.close()---def test_change_cwd():- sandbox = Sandbox(cwd="/code/app")-- # change dir to /home/user- sandbox.cwd = "/home/user"-- # process respects cwd- proc = sandbox.process.start("pwd")- output = proc.wait()- assert output.stdout == "/home/user"-- # filesystem respects cwd- sandbox.filesystem.write("hello.txt", "Hello VM!")- proc = sandbox.process.start("cat /home/user/hello.txt")- output = proc.wait()- assert output.stdout == "Hello VM!"-- sandbox.close()---def test_initial_cwd_with_tilde():- sandbox = Sandbox(cwd="~/code/")-- proc = sandbox.process.start("pwd")- output = proc.wait()- assert output.stdout == "/home/user/code"-- sandbox.close()---def test_relative_paths():- sandbox = Sandbox(cwd="/home/user")-- sandbox.filesystem.make_dir("./code")- sandbox.filesystem.write("./code/hello.txt", "Hello Vasek!")- proc = sandbox.process.start("cat /home/user/code/hello.txt")- output = proc.wait()- assert output.stdout == "Hello Vasek!"-- sandbox.filesystem.write("../../hello.txt", "Hello Tom!")- proc = sandbox.process.start("cat /hello.txt")- output = proc.wait()- assert output.stdout == "Hello Tom!"-- sandbox.close()---def test_warnings():- sandbox = Sandbox()-- with pytest.warns(Warning):- sandbox.filesystem.write("./hello.txt", "Hello Vasek!")-- with pytest.warns(Warning):- sandbox.filesystem.write("../hello.txt", "Hello Vasek!")-- with pytest.warns(Warning):- sandbox.filesystem.write("~/hello.txt", "Hello Vasek!")-- sandbox.close()---def test_doesnt_exists():- sandbox = Sandbox()-- with pytest.raises(CurrentWorkingDirectoryDoesntExistException):- sandbox.process.start("ls", cwd="/this/doesnt/exist")-- sandbox.close()diff --git a/packages/python-sdk/tests/test_env_vars.py b/packages/python-sdk/tests/test_env_vars.pydeleted file mode 100644index 899e8a8bd..000000000--- a/packages/python-sdk/tests/test_env_vars.py+++ /dev/null@@ -1,45 +0,0 @@-from e2b import Sandbox---def test_env_vars():- sandbox = Sandbox()-- process = sandbox.process.start("echo $FOO", env_vars={"FOO": "BAR"})- process.wait()- output = process.stdout- assert output == "BAR"-- sandbox.close()---def test_profile_env_vars():- sandbox = Sandbox()-- sandbox.filesystem.write("/home/user/.profile", "export FOO=BAR")- process = sandbox.process.start("echo $FOO")- process.wait()- output = process.stdout- assert output == "BAR"-- sandbox.close()---def test_default_env_vars():- sandbox = Sandbox(env_vars={"FOO": "BAR"})- process = sandbox.process.start("echo $FOO")- process.wait()- output = process.stdout- assert output == "BAR"-- sandbox.close()---def test_overriding_env_vars():- sandbox = Sandbox(env_vars={"FOO": "BAR"})-- process = sandbox.process.start("echo $FOO", env_vars={"FOO": "QUX"})- process.wait()- output = process.stdout- assert output == "QUX"-- sandbox.close()diff --git a/packages/python-sdk/tests/test_file_upload_download.py b/packages/python-sdk/tests/test_file_upload_download.pydeleted file mode 100644index 9cab56ad8..000000000--- a/packages/python-sdk/tests/test_file_upload_download.py+++ /dev/null@@ -1,27 +0,0 @@-import filecmp--from os import path-from e2b import Sandbox---def test_download():- file_name = "video.webm"- local_dir = "tests/assets"-- local_path = path.join(local_dir, file_name)-- sandbox = Sandbox()-- # Upload the file first (it's uploaded to /home/user)- with open(local_path, "rb") as f:- uploaded_file_path = sandbox.upload_file(file=f)-- # Download the file back and save it in the local filesystem- file_content = sandbox.download_file(uploaded_file_path)- with open(path.join(local_dir, "video-downloaded.webm"), "wb") as f:- f.write(file_content)-- # Compare the downloaded file with the original- assert filecmp.cmp(local_path, path.join(local_dir, "video-downloaded.webm"))-- sandbox.close()diff --git a/packages/python-sdk/tests/test_filesystem.py b/packages/python-sdk/tests/test_filesystem.pydeleted file mode 100644index 66e421b00..000000000--- a/packages/python-sdk/tests/test_filesystem.py+++ /dev/null@@ -1,134 +0,0 @@-import filecmp--from os import path-from time import sleep-from typing import List--from e2b import Sandbox, FilesystemEvent---def test_list_files():- sandbox = Sandbox()- sandbox.filesystem.make_dir("/test/new")-- ls = sandbox.filesystem.list("/test")- assert ["new"] == [x.name for x in ls]-- sandbox.close()---def test_create_file():- sandbox = Sandbox()- sandbox.filesystem.make_dir("/test")- sandbox.filesystem.write("/test/test.txt", "Hello World!")-- ls = sandbox.filesystem.list("/test")- assert ["test.txt"] == [x.name for x in ls]-- sandbox.close()---def test_read_and_write():- sandbox = Sandbox()-- sandbox.filesystem.write("/tmp/test.txt", "Hello World!")-- content = sandbox.filesystem.read("/tmp/test.txt")- assert content == "Hello World!"-- sandbox.close()---def test_list_delete_files():- sandbox = Sandbox()- sandbox.filesystem.make_dir("/test/new")-- ls = sandbox.filesystem.list("/test")- assert ["new"] == [x.name for x in ls]-- sandbox.filesystem.remove("/test/new")-- ls = sandbox.filesystem.list("/test")- assert [] == [x.name for x in ls]-- sandbox.close()---def test_watch_dir():- sandbox = Sandbox()- sandbox.filesystem.write("/tmp/test.txt", "Hello")-- watcher = sandbox.filesystem.watch_dir("/tmp")-- events: List[FilesystemEvent] = []- watcher.add_event_listener(lambda e: events.append(e))-- watcher.start()- sandbox.filesystem.write("/tmp/test.txt", "World!")- sleep(1)- watcher.stop()-- assert len(events) >= 1-- event = events[0]- assert event.operation == "Write"- assert event.path == "/tmp/test.txt"-- sandbox.close()---def test_write_bytes():- file_name = "video.webm"- local_dir = "tests/assets"- remote_dir = "/tmp"-- local_path = path.join(local_dir, file_name)- remote_path = path.join(remote_dir, file_name)-- # TODO: This test isn't complete since we can't verify the size of the file inside sandbox.- # We don't have any SDK function to get the size of a file inside sandbox.-- sandbox = Sandbox()-- # Upload the file- with open(local_path, "rb") as f:- content = f.read()- sandbox.filesystem.write_bytes(remote_path, content)-- # Check if the file exists inside sandbox- files = sandbox.filesystem.list(remote_dir)- assert file_name in [x.name for x in files]-- sandbox.close()---def test_read_bytes():- file_name = "video.webm"- local_dir = "tests/assets"- remote_dir = "/tmp"-- local_path = path.join(local_dir, file_name)- remote_path = path.join(remote_dir, file_name)-- # TODO: This test isn't complete since we can't verify the size of the file inside sandbox.- # We don't have any SDK function to get the size of a file inside sandbox.-- sandbox = Sandbox()-- # Upload the file first- with open(local_path, "rb") as f:- content = f.read()- sandbox.filesystem.write_bytes(remote_path, content)-- # Download the file- content = sandbox.filesystem.read_bytes(remote_path)-- # Save the file- downloaded_path = path.join(local_dir, "video-downloaded.webm")- with open(downloaded_path, "wb") as f:- f.write(content)-- # Compare if both files are equal- assert filecmp.cmp(local_path, downloaded_path)-- sandbox.close()diff --git a/packages/python-sdk/tests/test_kill_sandbox.py b/packages/python-sdk/tests/test_kill_sandbox.pydeleted file mode 100644index 79a46f91a..000000000--- a/packages/python-sdk/tests/test_kill_sandbox.py+++ /dev/null@@ -1,11 +0,0 @@-from e2b import Sandbox---def test_kill_sandbox():- s = Sandbox()- Sandbox.kill(s.id)-- sandboxes = Sandbox.list()- assert s.id not in [sandbox.sandbox_id for sandbox in sandboxes]-- s.close()diff --git a/packages/python-sdk/tests/test_list_sandboxes.py b/packages/python-sdk/tests/test_list_sandboxes.pydeleted file mode 100644index a1c1f66b2..000000000--- a/packages/python-sdk/tests/test_list_sandboxes.py+++ /dev/null@@ -1,23 +0,0 @@-from e2b import Sandbox---def test_list_running_sandboxes():- sandboxes = []- for i in range(3):- sandboxes.append(Sandbox(metadata={"n": f"py{i}"}))-- running_sandboxes = list(- filter(- lambda s: s.metadata and s.metadata.get("n", "").startswith("py"),- Sandbox.list(),- )- )- assert len(running_sandboxes) == 3- assert set(map(lambda x: x.metadata["n"], running_sandboxes)) == {- "py0",- "py1",- "py2",- }-- for sandbox in sandboxes:- sandbox.close()diff --git a/packages/python-sdk/tests/test_process.py b/packages/python-sdk/tests/test_process.pydeleted file mode 100644index a8e85052a..000000000--- a/packages/python-sdk/tests/test_process.py+++ /dev/null@@ -1,141 +0,0 @@-from unittest.mock import MagicMock--from e2b import Sandbox---def test_process_expected_stdout():- # TODO: Implement this once we fix envd stdout/stderr race condition- pass---def test_process_expected_stderr():- # TODO: Implement this once we fix envd stdout/stderr race condition- pass---def test_process_on_stdout_stderr():- sandbox = Sandbox()-- stdout = []- stderr = []-- proc = sandbox.process.start(- "pwd",- on_stdout=lambda data: stdout.append(data),- on_stderr=lambda data: stderr.append(data),- cwd="/tmp",- )-- output = proc.wait()-- assert not output.error- assert output.stdout == "/tmp"- assert output.stderr == ""- assert list(map(lambda message: message.line, stdout)) == ["/tmp"]- assert stderr == []- assert proc.exit_code == 0-- sandbox.close()---def test_process_on_exit():- sandbox = Sandbox()-- on_exit = MagicMock()-- proc = sandbox.process.start(- "pwd",- on_exit=lambda exit_code: on_exit(exit_code),- )-- proc.wait()- on_exit.assert_called_once()-- sandbox.close()---def test_process_send_stdin():- sandbox = Sandbox()-- proc = sandbox.process.start(- 'read -r line; echo "$line"',- cwd="/code",- )- proc.send_stdin("ping\n")- proc.wait()-- assert proc.output.stdout == "ping"-- assert len(proc.output_messages) == 1- message = proc.output_messages[0]- assert message.line == "ping"- assert not message.error-- sandbox.close()---def test_default_on_exit():- on_exit = MagicMock()-- sandbox = Sandbox(on_exit=lambda exit_code: on_exit(exit_code))- proc = sandbox.process.start(- "pwd",- on_exit=lambda: print("EXIT"),- )- proc.wait()- on_exit.assert_not_called()-- proc = sandbox.process.start(- "pwd",- )- proc.wait()- on_exit.assert_called_once()-- sandbox.close()---def test_process_default_on_stdout_stderr():- on_stdout = MagicMock()- on_stderr = MagicMock()-- sandbox = Sandbox(- on_stdout=lambda data: on_stdout(),- on_stderr=lambda data: on_stderr(),- )- code = "node -e \"console.log('hello'); throw new Error('error')\""-- stdout = []- stderr = []-- proc = sandbox.process.start(- code,- on_stdout=lambda data: stdout.append(data),- on_stderr=lambda data: stderr.append(data),- )-- proc.wait()- on_stdout.assert_not_called()- on_stderr.assert_not_called()-- proc = sandbox.process.start(code)- proc.wait()-- on_stdout.assert_called_once()- on_stderr.assert_called()- assert proc.exit_code == 1-- sandbox.close()---def test_process_start_and_wait():- sandbox = Sandbox()- code = "node -e \"console.log('hello');\""-- output = sandbox.process.start_and_wait(code)-- proc = sandbox.process.start(code)- proc.wait()-- assert output.exit_code == 0-- sandbox.close()diff --git a/packages/python-sdk/tests/test_session.py b/packages/python-sdk/tests/test_session.pydeleted file mode 100644index 4390b3858..000000000--- a/packages/python-sdk/tests/test_session.py+++ /dev/null@@ -1,13 +0,0 @@-from e2b import Sandbox---def test_create_sandbox():- sandbox = Sandbox()- sandbox.close()---def test_create_multiple_sandboxes():- sandbox = Sandbox()- sandbox2 = Sandbox()- sandbox.close()- sandbox2.close()diff --git a/packages/python-sdk/tests/test_timeout.py b/packages/python-sdk/tests/test_timeout.pydeleted file mode 100644index 2ff79ce84..000000000--- a/packages/python-sdk/tests/test_timeout.py+++ /dev/null@@ -1,45 +0,0 @@-from typing import Optional--import pytest--from e2b import Sandbox-from e2b.sandbox.exceptions import TimeoutException---def test_create_sandbox_timeout():- sandbox: Optional[Sandbox] = None-- with pytest.raises(TimeoutException):- sandbox = Sandbox(timeout=0.01)-- if sandbox:- sandbox.close()---def test_process_timeout():- sandbox: Optional[Sandbox] = None-- with pytest.raises(TimeoutException):- sandbox = Sandbox()- sandbox.process.start(- "sleep 1",- timeout=0.01,- )-- if sandbox:- sandbox.close()---def test_filesystem_timeout():- sandbox: Optional[Sandbox] = None-- with pytest.raises(TimeoutException):- sandbox = Sandbox()- sandbox.filesystem.write(- "test.txt",- "Hello World",- timeout=0.001,- )-- if sandbox:- sandbox.close()