Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
chore: distinguish between Sandbox and file not found (#1231)
Jakub Novák5a673d15c82b
diff --git a/.changeset/slimy-snakes-grab.md b/.changeset/slimy-snakes-grab.mdnew file mode 100644index 000000000..483871110--- /dev/null+++ b/.changeset/slimy-snakes-grab.md@@ -0,0 +1,6 @@+---+'@e2b/python-sdk': patch+'e2b': patch+---++chore: distinguish between Sandbox and file not founddiff --git a/packages/js-sdk/src/envd/api.ts b/packages/js-sdk/src/envd/api.tsindex 960a03ded..b0bd1704c 100644--- a/packages/js-sdk/src/envd/api.ts+++ b/packages/js-sdk/src/envd/api.ts@@ -8,6 +8,7 @@ import {InvalidArgumentError,NotFoundError,NotEnoughSpaceError,+ SandboxNotFoundError,formatSandboxTimeoutError,AuthenticationError,} from '../errors'@@ -17,10 +18,30 @@ import { WatchDirResponse } from './filesystem/filesystem_pb'type ApiError = { message?: string } | string-export async function handleEnvdApiError(res: {- error?: ApiError- response: Response-}) {+const DEFAULT_ERROR_MAP: Record<number, (message: string) => Error> = {+ 400: (message) => new InvalidArgumentError(message),+ 401: (message) => new AuthenticationError(message),+ 404: (message) => new NotFoundError(message),+ 429: (message) =>+ new SandboxError(`${message}: The requests are being rate limited.`),+ 502: formatSandboxTimeoutError,+ 507: (message) => new NotEnoughSpaceError(message),+}++/**+ * Handles errors from envd API responses by mapping HTTP status codes to specific error types.+ *+ * @param res - The API response object containing an optional error and the raw `Response`.+ * @param errorMap - Optional map of HTTP status codes to error factory functions that override the defaults.+ * @returns The corresponding `Error` instance if an error is present, or `undefined` if the response is successful.+ */+export async function handleEnvdApiError(+ res: {+ error?: ApiError+ response: Response+ },+ errorMap?: Record<number, (message: string) => Error>+) {if (!res.error) {return}@@ -30,24 +51,18 @@ export async function handleEnvdApiError(res: {? res.error: res.error?.message || (await res.response.text())- switch (res.response.status) {- case 400:- return new InvalidArgumentError(message)- case 401:- return new AuthenticationError(message)- case 404:- return new NotFoundError(message)- case 429:- return new SandboxError(- `${res.response.status}: ${message}: The requests are being rate limited.`- )- case 502:- return formatSandboxTimeoutError(message)- case 507:- return new NotEnoughSpaceError(message)- default:- return new SandboxError(`${res.response.status}: ${message}`)+ // Check if a custom error mapping is provided for this error code+ if (errorMap && res.response.status in errorMap) {+ return errorMap[res.response.status]?.(message)}++ // Check if there is a default error mapping for this error code+ if (res.response.status in DEFAULT_ERROR_MAP) {+ return DEFAULT_ERROR_MAP[res.response.status]?.(message)+ }++ // Fallback to a generic SandboxError if no specific mapping is found+ return new SandboxError(`${res.response.status}: ${message}`)}export async function handleProcessStartEvent(@@ -60,7 +75,9 @@ export async function handleProcessStartEvent(} catch (err) {if (err instanceof ConnectError) {if (err.code === Code.Unavailable) {- throw new NotFoundError('Sandbox is probably not running anymore')+ throw new SandboxNotFoundError(+ 'Sandbox is probably not running anymore'+ )}}@@ -83,7 +100,9 @@ export async function handleWatchDirStartEvent(} catch (err) {if (err instanceof ConnectError) {if (err.code === Code.Unavailable) {- throw new NotFoundError('Sandbox is probably not running anymore')+ throw new SandboxNotFoundError(+ 'Sandbox is probably not running anymore'+ )}}diff --git a/packages/js-sdk/src/envd/rpc.ts b/packages/js-sdk/src/envd/rpc.tsindex 9ad34ec6e..10d64282b 100644--- a/packages/js-sdk/src/envd/rpc.ts+++ b/packages/js-sdk/src/envd/rpc.ts@@ -13,28 +13,45 @@ import {} from '../errors'import { ENVD_DEFAULT_USER } from './versions'-export function handleRpcError(err: unknown): Error {+const DEFAULT_ERROR_MAP: Partial<Record<Code, (message: string) => Error>> = {+ [Code.InvalidArgument]: (message) => new InvalidArgumentError(message),+ [Code.Unauthenticated]: (message) => new AuthenticationError(message),+ [Code.NotFound]: (message) => new NotFoundError(message),+ [Code.Unavailable]: formatSandboxTimeoutError,+ [Code.Canceled]: (message) =>+ new TimeoutError(+ `${message}: This error is likely due to exceeding 'requestTimeoutMs'. You can pass the request timeout value as an option when making the request.`+ ),+ [Code.DeadlineExceeded]: (message) =>+ new TimeoutError(+ `${message}: This error is likely due to exceeding 'timeoutMs' — the total time a long running request (like command execution or directory watch) can be active. It can be modified by passing 'timeoutMs' when making the request. Use '0' to disable the timeout.`+ ),+}++/**+ * Handles errors from envd RPC calls by mapping gRPC status codes to specific error types.+ *+ * @param err - The caught error, expected to be a `ConnectError` from the gRPC transport.+ * @param errorMap - Optional map of gRPC `Code` values to error factory functions that override the defaults.+ * @returns The corresponding `Error` instance mapped from the gRPC status code, or the original error if it is not a `ConnectError`.+ */+export function handleRpcError(+ err: unknown,+ errorMap?: Partial<Record<Code, (message: string) => Error>>+): Error {if (err instanceof ConnectError) {- switch (err.code) {- case Code.InvalidArgument:- return new InvalidArgumentError(err.message)- case Code.Unauthenticated:- return new AuthenticationError(err.message)- case Code.NotFound:- return new NotFoundError(err.message)- case Code.Unavailable:- return formatSandboxTimeoutError(err.message)- case Code.Canceled:- return new TimeoutError(- `${err.message}: This error is likely due to exceeding 'requestTimeoutMs'. You can pass the request timeout value as an option when making the request.`- )- case Code.DeadlineExceeded:- return new TimeoutError(- `${err.message}: This error is likely due to exceeding 'timeoutMs' — the total time a long running request (like command execution or directory watch) can be active. It can be modified by passing 'timeoutMs' when making the request. Use '0' to disable the timeout.`- )- default:- return new SandboxError(`${err.code}: ${err.message}`)+ // Check if a custom error mapping is provided for this error code+ if (errorMap && err.code in errorMap) {+ return errorMap[err.code]!(err.message)}++ // Check if there is a default error mapping for this error code+ if (err.code in DEFAULT_ERROR_MAP) {+ return DEFAULT_ERROR_MAP[err.code]!(err.message)+ }++ // Fallback to a generic SandboxError if no specific mapping is found+ return new SandboxError(`${err.code}: ${err.message}`)}return err as Errordiff --git a/packages/js-sdk/src/errors.ts b/packages/js-sdk/src/errors.tsindex ad51c1f2a..7305083c5 100644--- a/packages/js-sdk/src/errors.ts+++ b/packages/js-sdk/src/errors.ts@@ -60,6 +60,8 @@ export class NotEnoughSpaceError extends SandboxError {/*** Thrown when a resource is not found.+ *+ * @deprecated Use {@link FileNotFoundError} or {@link SandboxNotFoundError} instead. This class will be removed in the next major version.*/export class NotFoundError extends SandboxError {constructor(message: string, stackTrace?: string) {@@ -68,6 +70,26 @@ export class NotFoundError extends SandboxError {}}+/**+ * Thrown when a file or directory is not found inside a sandbox.+ */+export class FileNotFoundError extends NotFoundError {+ constructor(message: string, stackTrace?: string) {+ super(message, stackTrace)+ this.name = 'FileNotFoundError'+ }+}++/**+ * Thrown when a sandbox is not found (e.g. it doesn't exist or is no longer running).+ */+export class SandboxNotFoundError extends NotFoundError {+ constructor(message: string, stackTrace?: string) {+ super(message, stackTrace)+ this.name = 'SandboxNotFoundError'+ }+}+/*** Thrown when authentication fails.*/diff --git a/packages/js-sdk/src/index.ts b/packages/js-sdk/src/index.tsindex 17d4a9752..d3a93d68d 100644--- a/packages/js-sdk/src/index.ts+++ b/packages/js-sdk/src/index.ts@@ -5,12 +5,14 @@ export { ConnectionConfig } from './connectionConfig'export type { ConnectionOpts, Username } from './connectionConfig'export {AuthenticationError,+ FileNotFoundError,GitAuthError,GitUpstreamError,InvalidArgumentError,NotEnoughSpaceError,NotFoundError,SandboxError,+ SandboxNotFoundError,TemplateError,TimeoutError,RateLimitError,diff --git a/packages/js-sdk/src/sandbox/filesystem/index.ts b/packages/js-sdk/src/sandbox/filesystem/index.tsindex e57bb8d12..5a15602ec 100644--- a/packages/js-sdk/src/sandbox/filesystem/index.ts+++ b/packages/js-sdk/src/sandbox/filesystem/index.ts@@ -31,9 +31,34 @@ import {ENVD_DEFAULT_USER,ENVD_VERSION_RECURSIVE_WATCH,} from '../../envd/versions'-import { InvalidArgumentError, TemplateError } from '../../errors'+import {+ FileNotFoundError,+ InvalidArgumentError,+ TemplateError,+} from '../../errors'import { toBlob } from '../../utils'+const FILESYSTEM_HTTP_ERROR_MAP: Record<number, (message: string) => Error> = {+ 404: (message: string) => new FileNotFoundError(message),+}++const FILESYSTEM_RPC_ERROR_MAP: Partial<+ Record<Code, (message: string) => Error>+> = {+ [Code.NotFound]: (message: string) => new FileNotFoundError(message),+}++function handleFilesystemRpcError(err: unknown): Error {+ return handleRpcError(err, FILESYSTEM_RPC_ERROR_MAP)+}++function handleFilesystemEnvdApiError(res: {+ error?: { message?: string } | string+ response: Response+}) {+ return handleEnvdApiError(res, FILESYSTEM_HTTP_ERROR_MAP)+}+/*** Sandbox filesystem object information.*/@@ -270,7 +295,7 @@ export class Filesystem {signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),})- const err = await handleEnvdApiError(res)+ const err = await handleFilesystemEnvdApiError(res)if (err) {throw err}@@ -381,7 +406,7 @@ export class Filesystem {body: {},})- const err = await handleEnvdApiError(res)+ const err = await handleFilesystemEnvdApiError(res)if (err) {throw err}@@ -464,7 +489,7 @@ export class Filesystem {return entries} catch (err) {- throw handleRpcError(err)+ throw handleFilesystemRpcError(err)}}@@ -494,7 +519,7 @@ export class Filesystem {}}- throw handleRpcError(err)+ throw handleFilesystemRpcError(err)}}@@ -542,7 +567,7 @@ export class Filesystem {symlinkTarget: entry.symlinkTarget,}} catch (err) {- throw handleRpcError(err)+ throw handleFilesystemRpcError(err)}}@@ -562,7 +587,7 @@ export class Filesystem {})} catch (err) {- throw handleRpcError(err)+ throw handleFilesystemRpcError(err)}}@@ -592,7 +617,7 @@ export class Filesystem {}}- throw handleRpcError(err)+ throw handleFilesystemRpcError(err)}}@@ -636,7 +661,7 @@ export class Filesystem {symlinkTarget: res.entry.symlinkTarget,}} catch (err) {- throw handleRpcError(err)+ throw handleFilesystemRpcError(err)}}@@ -705,7 +730,7 @@ export class Filesystem {opts?.onExit)} catch (err) {- throw handleRpcError(err)+ throw handleFilesystemRpcError(err)}}}diff --git a/packages/js-sdk/src/sandbox/sandboxApi.ts b/packages/js-sdk/src/sandbox/sandboxApi.tsindex fec8003c4..f608a9b5b 100644--- a/packages/js-sdk/src/sandbox/sandboxApi.ts+++ b/packages/js-sdk/src/sandbox/sandboxApi.ts@@ -5,7 +5,7 @@ import {DEFAULT_SANDBOX_TIMEOUT_MS,} from '../connectionConfig'import { compareVersions } from 'compare-versions'-import { NotFoundError, TemplateError } from '../errors'+import { SandboxNotFoundError, TemplateError } from '../errors'import { timeoutToSeconds } from '../utils'import type { McpServer as BaseMcpServer } from './mcp'@@ -512,7 +512,7 @@ export class SandboxApi {})if (res.error?.code === 404) {- throw new NotFoundError(`Sandbox ${sandboxId} not found`)+ throw new SandboxNotFoundError(`Sandbox ${sandboxId} not found`)}const err = handleApiError(res)@@ -535,7 +535,7 @@ export class SandboxApi {})if (res.error?.code === 404) {- throw new NotFoundError(`Sandbox ${sandboxId} not found`)+ throw new SandboxNotFoundError(`Sandbox ${sandboxId} not found`)}const err = handleApiError(res)@@ -588,7 +588,7 @@ export class SandboxApi {})if (res.error?.code === 404) {- throw new NotFoundError(`Sandbox ${sandboxId} not found`)+ throw new SandboxNotFoundError(`Sandbox ${sandboxId} not found`)}if (res.error?.code === 409) {@@ -644,7 +644,7 @@ export class SandboxApi {})if (res.error?.code === 404) {- throw new NotFoundError(`Sandbox ${sandboxId} not found`)+ throw new SandboxNotFoundError(`Sandbox ${sandboxId} not found`)}const err = handleApiError(res)@@ -782,7 +782,7 @@ export class SandboxApi {})if (res.error?.code === 404) {- throw new NotFoundError(`Paused sandbox ${sandboxId} not found`)+ throw new SandboxNotFoundError(`Paused sandbox ${sandboxId} not found`)}const err = handleApiError(res)diff --git a/packages/js-sdk/tests/sandbox/connect.test.ts b/packages/js-sdk/tests/sandbox/connect.test.tsindex 2a5efc060..3e3f77259 100644--- a/packages/js-sdk/tests/sandbox/connect.test.ts+++ b/packages/js-sdk/tests/sandbox/connect.test.ts@@ -41,7 +41,7 @@ sandboxTest.skipIf(isDebug)(const connectPromise = Sandbox.connect(sandbox.sandboxId)await expect(connectPromise).rejects.toThrowError(expect.objectContaining({- name: 'NotFoundError',+ name: 'SandboxNotFoundError',}))}diff --git a/packages/js-sdk/tests/sandbox/files/info.test.ts b/packages/js-sdk/tests/sandbox/files/info.test.tsindex ee91ed7e0..7e5bd4669 100644--- a/packages/js-sdk/tests/sandbox/files/info.test.ts+++ b/packages/js-sdk/tests/sandbox/files/info.test.ts@@ -1,6 +1,6 @@import { assert } from 'vitest'import { expect } from 'vitest'-import { NotFoundError } from '../../../src/errors.js'+import { FileNotFoundError } from '../../../src/errors.js'import { sandboxTest } from '../../setup.js'@@ -24,7 +24,9 @@ sandboxTest('get info of a file', async ({ sandbox }) => {sandboxTest('get info of a file that does not exist', async ({ sandbox }) => {const filename = 'test_does_not_exist.txt'- await expect(sandbox.files.getInfo(filename)).rejects.toThrow(NotFoundError)+ await expect(sandbox.files.getInfo(filename)).rejects.toThrow(+ FileNotFoundError+ )})sandboxTest('get info of a directory', async ({ sandbox }) => {@@ -50,7 +52,9 @@ sandboxTest(async ({ sandbox }) => {const dirname = 'test_does_not_exist_dir'- await expect(sandbox.files.getInfo(dirname)).rejects.toThrow(NotFoundError)+ await expect(sandbox.files.getInfo(dirname)).rejects.toThrow(+ FileNotFoundError+ )})diff --git a/packages/js-sdk/tests/sandbox/files/read.test.ts b/packages/js-sdk/tests/sandbox/files/read.test.tsindex 7479e9df5..4dad2fb33 100644--- a/packages/js-sdk/tests/sandbox/files/read.test.ts+++ b/packages/js-sdk/tests/sandbox/files/read.test.ts@@ -1,6 +1,6 @@import { expect, assert } from 'vitest'-import { NotFoundError } from '../../../src'+import { FileNotFoundError, NotFoundError } from '../../../src'import { sandboxTest } from '../../setup.js'sandboxTest('read file', async ({ sandbox }) => {@@ -15,9 +15,22 @@ sandboxTest('read file', async ({ sandbox }) => {sandboxTest('read non-existing file', async ({ sandbox }) => {const filename = 'non_existing_file.txt'- await expect(sandbox.files.read(filename)).rejects.toThrowError(NotFoundError)+ await expect(sandbox.files.read(filename)).rejects.toThrowError(+ FileNotFoundError+ )})+sandboxTest(+ 'read non-existing file catches with deprecated NotFoundError',+ async ({ sandbox }) => {+ const filename = 'non_existing_file.txt'++ await expect(sandbox.files.read(filename)).rejects.toThrowError(+ NotFoundError+ )+ }+)+sandboxTest('empty file', async ({ sandbox }) => {const filename = 'empty-file.txt'diff --git a/packages/js-sdk/tests/sandbox/files/rename.test.ts b/packages/js-sdk/tests/sandbox/files/rename.test.tsindex 936162172..d85e9db53 100644--- a/packages/js-sdk/tests/sandbox/files/rename.test.ts+++ b/packages/js-sdk/tests/sandbox/files/rename.test.ts@@ -1,6 +1,6 @@import { assert, expect } from 'vitest'-import { NotFoundError } from '../../../src'+import { FileNotFoundError } from '../../../src'import { sandboxTest } from '../../setup.js'sandboxTest('rename file', async ({ sandbox }) => {@@ -28,5 +28,5 @@ sandboxTest('rename non-existing file', async ({ sandbox }) => {await expect(sandbox.files.rename(oldFilename, newFilename)- ).rejects.toThrowError(NotFoundError)+ ).rejects.toThrowError(FileNotFoundError)})diff --git a/packages/js-sdk/tests/sandbox/files/watch.test.ts b/packages/js-sdk/tests/sandbox/files/watch.test.tsindex f0271f706..c1f81c6a6 100644--- a/packages/js-sdk/tests/sandbox/files/watch.test.ts+++ b/packages/js-sdk/tests/sandbox/files/watch.test.ts@@ -1,7 +1,11 @@import { expect, onTestFinished } from 'vitest'import { isDebug, sandboxTest } from '../../setup.js'-import { FilesystemEventType, NotFoundError, SandboxError } from '../../../src'+import {+ FileNotFoundError,+ FilesystemEventType,+ SandboxError,+} from '../../../src'sandboxTest('watch directory changes', async ({ sandbox }) => {const dirname = 'test_watch_dir'@@ -138,7 +142,7 @@ sandboxTest('watch non-existing directory', async ({ sandbox }) => {const dirname = 'non_existing_watch_dir'await expect(sandbox.files.watchDir(dirname, () => {})).rejects.toThrowError(- NotFoundError+ FileNotFoundError)})diff --git a/packages/python-sdk/e2b/__init__.py b/packages/python-sdk/e2b/__init__.pyindex 264fd5dee..cb89f394a 100644--- a/packages/python-sdk/e2b/__init__.py+++ b/packages/python-sdk/e2b/__init__.py@@ -35,6 +35,7 @@ from .connection_config import ()from .exceptions import (AuthenticationException,+ FileNotFoundException,GitAuthException,GitUpstreamException,BuildException,@@ -43,6 +44,7 @@ from .exceptions import (NotEnoughSpaceException,NotFoundException,SandboxException,+ SandboxNotFoundException,TemplateException,TimeoutException,)@@ -122,6 +124,8 @@ __all__ = ["SandboxException","TimeoutException","NotFoundException",+ "FileNotFoundException",+ "SandboxNotFoundException","AuthenticationException","GitAuthException","GitUpstreamException",diff --git a/packages/python-sdk/e2b/envd/api.py b/packages/python-sdk/e2b/envd/api.pyindex 2c5670d5d..7e2a59c13 100644--- a/packages/python-sdk/e2b/envd/api.py+++ b/packages/python-sdk/e2b/envd/api.py@@ -1,6 +1,8 @@import httpximport json+from typing import Callable, Optional+from e2b.exceptions import (SandboxException,NotFoundException,@@ -14,6 +16,17 @@ from e2b.exceptions import (ENVD_API_FILES_ROUTE = "/files"ENVD_API_HEALTH_ROUTE = "/health"+_DEFAULT_API_ERROR_MAP: dict[int, Callable[[str], Exception]] = {+ 400: InvalidArgumentException,+ 401: AuthenticationException,+ 404: NotFoundException,+ 429: lambda message: SandboxException(+ f"{message}: The requests are being rate limited."+ ),+ 502: format_sandbox_timeout_exception,+ 507: NotEnoughSpaceException,+}+def get_message(e: httpx.Response) -> str:try:@@ -24,36 +37,53 @@ def get_message(e: httpx.Response) -> str:return message-def handle_envd_api_exception(res: httpx.Response):+def handle_envd_api_exception(+ res: httpx.Response,+ error_map: Optional[dict[int, Callable[[str], Exception]]] = None,+):+ """Handle errors from envd API responses by mapping HTTP status codes to specific exception types.++ :param res: The HTTP response.+ :param error_map: Optional map of HTTP status codes to exception factories that override the defaults.+ :return: The corresponding exception, or ``None`` if the response is successful.+ """if res.is_success:returnres.read()- return format_envd_api_exception(res.status_code, get_message(res))+ return format_envd_api_exception(res.status_code, get_message(res), error_map)-async def ahandle_envd_api_exception(res: httpx.Response):+async def ahandle_envd_api_exception(+ res: httpx.Response,+ error_map: Optional[dict[int, Callable[[str], Exception]]] = None,+):+ """Async version of :func:`handle_envd_api_exception`."""if res.is_success:returnawait res.aread()- return format_envd_api_exception(res.status_code, get_message(res))---def format_envd_api_exception(status_code: int, message: str):- if status_code == 400:- return InvalidArgumentException(message)- elif status_code == 401:- return AuthenticationException(message)- elif status_code == 404:- return NotFoundException(message)- elif status_code == 429:- return SandboxException(f"{message}: The requests are being rate limited.")- elif status_code == 502:- return format_sandbox_timeout_exception(message)- elif status_code == 507:- return NotEnoughSpaceException(message)- else:- return SandboxException(f"{status_code}: {message}")+ return format_envd_api_exception(res.status_code, get_message(res), error_map)+++def format_envd_api_exception(+ status_code: int,+ message: str,+ error_map: Optional[dict[int, Callable[[str], Exception]]] = None,+):+ """Map an HTTP status code and message to the appropriate exception.++ :param status_code: The HTTP status code.+ :param message: The error message from the response body.+ :param error_map: Optional map of HTTP status codes to exception factories that override the defaults.+ :return: The corresponding exception.+ """+ if error_map and status_code in error_map:+ return error_map[status_code](message)++ if status_code in _DEFAULT_API_ERROR_MAP:+ return _DEFAULT_API_ERROR_MAP[status_code](message)++ return SandboxException(f"{status_code}: {message}")diff --git a/packages/python-sdk/e2b/envd/rpc.py b/packages/python-sdk/e2b/envd/rpc.pyindex f8b2f3b9f..f8d263c5e 100644--- a/packages/python-sdk/e2b/envd/rpc.py+++ b/packages/python-sdk/e2b/envd/rpc.py@@ -1,6 +1,6 @@import base64-from typing import Optional+from typing import Callable, Optionalfrom packaging.version import Versionfrom e2b_connect.client import Code, ConnectException@@ -16,31 +16,41 @@ from e2b.exceptions import (from e2b.connection_config import Username, default_usernamefrom e2b.envd.versions import ENVD_DEFAULT_USER+_DEFAULT_RPC_ERROR_MAP: dict[Code, Callable[[str], Exception]] = {+ Code.invalid_argument: InvalidArgumentException,+ Code.unauthenticated: AuthenticationException,+ Code.not_found: NotFoundException,+ Code.unavailable: format_sandbox_timeout_exception,+ Code.resource_exhausted: lambda message: RateLimitException(+ f"{message}: Rate limit exceeded, please try again later."+ ),+ Code.canceled: lambda message: TimeoutException(+ f"{message}: This error is likely due to exceeding 'request_timeout'. You can pass the request timeout value as an option when making the request."+ ),+ Code.deadline_exceeded: lambda message: TimeoutException(+ f"{message}: This error is likely due to exceeding 'timeout' — the total time a long running request (like process or directory watch) can be active. It can be modified by passing 'timeout' when making the request. Use '0' to disable the timeout."+ ),+}-def handle_rpc_exception(e: Exception):++def handle_rpc_exception(+ e: Exception,+ error_map: Optional[dict[Code, Callable[[str], Exception]]] = None,+):+ """Handle errors from envd RPC calls by mapping gRPC status codes to specific exception types.++ :param e: The caught exception, expected to be a ``ConnectException``.+ :param error_map: Optional map of gRPC codes to exception factories that override the defaults.+ :return: The corresponding exception, or the original exception if not a ``ConnectException``.+ """if isinstance(e, ConnectException):- if e.status == Code.invalid_argument:- return InvalidArgumentException(e.message)- elif e.status == Code.unauthenticated:- return AuthenticationException(e.message)- elif e.status == Code.not_found:- return NotFoundException(e.message)- elif e.status == Code.unavailable:- return format_sandbox_timeout_exception(e.message)- elif e.status == Code.resource_exhausted:- return RateLimitException(- f"{e.message}: Rate limit exceeded, please try again later."- )- elif e.status == Code.canceled:- return TimeoutException(- f"{e.message}: This error is likely due to exceeding 'request_timeout'. You can pass the request timeout value as an option when making the request."- )- elif e.status == Code.deadline_exceeded:- return TimeoutException(- f"{e.message}: This error is likely due to exceeding 'timeout' — the total time a long running request (like process or directory watch) can be active. It can be modified by passing 'timeout' when making the request. Use '0' to disable the timeout."- )- else:- return SandboxException(f"{e.status}: {e.message}")+ if error_map and e.status in error_map:+ return error_map[e.status](e.message)++ if e.status in _DEFAULT_RPC_ERROR_MAP:+ return _DEFAULT_RPC_ERROR_MAP[e.status](e.message)++ return SandboxException(f"{e.status}: {e.message}")else:return ediff --git a/packages/python-sdk/e2b/exceptions.py b/packages/python-sdk/e2b/exceptions.pyindex 75f5f6abf..6e9fe6530 100644--- a/packages/python-sdk/e2b/exceptions.py+++ b/packages/python-sdk/e2b/exceptions.py@@ -58,6 +58,26 @@ class NotEnoughSpaceException(SandboxException):class NotFoundException(SandboxException):"""Raised when a resource is not found.++ .. deprecated::+ Use :class:`FileNotFoundException` or :class:`SandboxNotFoundException` instead.+ This class will be removed in the next major version.+ """++ pass+++class FileNotFoundException(NotFoundException):+ """+ Raised when a file or directory is not found inside a sandbox.+ """++ pass+++class SandboxNotFoundException(NotFoundException):+ """+ Raised when a sandbox is not found (e.g. it doesn't exist or is no longer running)."""passdiff --git a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.pyindex d363553ee..f0c4c1cbc 100644--- a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py@@ -1,30 +1,54 @@+from io import IOBase, TextIOBase+from typing import IO, AsyncIterator, List, Literal, Optional, Union, overload+import httpcoreimport httpx-from io import IOBase, TextIOBasefrom packaging.version import Version-from typing import AsyncIterator, IO, List, Literal, Optional, overload, Union-from e2b.sandbox.filesystem.filesystem import WriteEntry+import e2b_connect as connectfrom e2b.connection_config import (+ KEEPALIVE_PING_HEADER,+ KEEPALIVE_PING_INTERVAL_SEC,ConnectionConfig,Username,default_username,- KEEPALIVE_PING_HEADER,- KEEPALIVE_PING_INTERVAL_SEC,)from e2b.envd.api import ENVD_API_FILES_ROUTE, ahandle_envd_api_exceptionfrom e2b.envd.filesystem import filesystem_connect, filesystem_pb2from e2b.envd.rpc import authentication_header, handle_rpc_exception-from e2b.envd.versions import ENVD_VERSION_RECURSIVE_WATCH, ENVD_DEFAULT_USER-from e2b.exceptions import SandboxException, TemplateException, InvalidArgumentException+from e2b.envd.versions import ENVD_DEFAULT_USER, ENVD_VERSION_RECURSIVE_WATCH+from e2b.exceptions import (+ FileNotFoundException,+ InvalidArgumentException,+ SandboxException,+ TemplateException,+)from e2b.sandbox.filesystem.filesystem import (- WriteInfo,EntryInfo,+ WriteEntry,+ WriteInfo,map_file_type,)from e2b.sandbox.filesystem.watch_handle import FilesystemEventfrom e2b.sandbox_async.filesystem.watch_handle import AsyncWatchHandlefrom e2b.sandbox_async.utils import OutputHandler+from e2b_connect.client import Code++_FILESYSTEM_RPC_ERROR_MAP = {+ Code.not_found: FileNotFoundException,+}++_FILESYSTEM_HTTP_ERROR_MAP = {+ 404: FileNotFoundException,+}+++def _handle_filesystem_rpc_exception(e: Exception) -> Exception:+ return handle_rpc_exception(e, _FILESYSTEM_RPC_ERROR_MAP)+++async def _ahandle_filesystem_envd_api_exception(r):+ return await ahandle_envd_api_exception(r, _FILESYSTEM_HTTP_ERROR_MAP)class Filesystem:@@ -136,7 +160,7 @@ class Filesystem:timeout=self._connection_config.get_request_timeout(request_timeout),)- err = await ahandle_envd_api_exception(r)+ err = await _ahandle_filesystem_envd_api_exception(r)if err:raise err@@ -234,7 +258,7 @@ class Filesystem:timeout=self._connection_config.get_request_timeout(request_timeout),)- err = await ahandle_envd_api_exception(r)+ err = await _ahandle_filesystem_envd_api_exception(r)if err:raise err@@ -301,7 +325,7 @@ class Filesystem:return entriesexcept Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)async def exists(self,@@ -333,7 +357,7 @@ class Filesystem:if isinstance(e, connect.ConnectException):if e.status == connect.Code.not_found:return False- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)async def get_info(self,@@ -376,7 +400,7 @@ class Filesystem:),)except Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)async def remove(self,@@ -400,7 +424,7 @@ class Filesystem:headers=authentication_header(self._envd_version, user),)except Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)async def rename(self,@@ -449,7 +473,7 @@ class Filesystem:),)except Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)async def make_dir(self,@@ -480,7 +504,7 @@ class Filesystem:if isinstance(e, connect.ConnectException):if e.status == connect.Code.already_exists:return False- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)async def watch_dir(self,@@ -533,4 +557,4 @@ class Filesystem:return AsyncWatchHandle(events=events, on_event=on_event, on_exit=on_exit)except Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)diff --git a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py b/packages/python-sdk/e2b/sandbox_async/sandbox_api.pyindex dc2547ffd..38f3cfd95 100644--- a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py+++ b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py@@ -30,8 +30,8 @@ from e2b.api.client.types import UNSETfrom e2b.api.client_async import get_api_clientfrom e2b.connection_config import ApiParams, ConnectionConfigfrom e2b.exceptions import (- NotFoundException,SandboxException,+ SandboxNotFoundException,TemplateException,)from e2b.sandbox.main import SandboxBase@@ -93,7 +93,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Sandbox {sandbox_id} not found")if res.status_code >= 300:raise handle_api_exception(res)@@ -153,7 +153,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Sandbox {sandbox_id} not found")if res.status_code >= 300:raise handle_api_exception(res)@@ -306,7 +306,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Sandbox {sandbox_id} not found")if res.status_code >= 300:raise handle_api_exception(res)@@ -356,7 +356,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Sandbox {sandbox_id} not found")if res.status_code == 409:return sandbox_id@@ -396,7 +396,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Paused sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Paused sandbox {sandbox_id} not found")if res.status_code >= 300:raise handle_api_exception(res)diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.pyindex 7f23d1133..a1d271f27 100644--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py@@ -1,33 +1,56 @@from io import IOBase, TextIOBase-from typing import IO, Iterator, List, Literal, Optional, overload, Union+from typing import IO, Iterator, List, Literal, Optional, Union, overload-from e2b.sandbox.filesystem.filesystem import WriteEntry--import e2b_connectimport httpcoreimport httpxfrom packaging.version import Version-from e2b.envd.versions import ENVD_VERSION_RECURSIVE_WATCH, ENVD_DEFAULT_USER-from e2b.exceptions import SandboxException, TemplateException, InvalidArgumentException+import e2b_connectfrom e2b.connection_config import (+ KEEPALIVE_PING_HEADER,+ KEEPALIVE_PING_INTERVAL_SEC,ConnectionConfig,Username,default_username,- KEEPALIVE_PING_HEADER,- KEEPALIVE_PING_INTERVAL_SEC,)+from e2b_connect.client import Code+from e2b.envd.api import ENVD_API_FILES_ROUTE, handle_envd_api_exceptionfrom e2b.envd.filesystem import filesystem_connect, filesystem_pb2from e2b.envd.rpc import authentication_header, handle_rpc_exception+from e2b.envd.versions import ENVD_DEFAULT_USER, ENVD_VERSION_RECURSIVE_WATCH+from e2b.exceptions import (+ FileNotFoundException,+ InvalidArgumentException,+ SandboxException,+ TemplateException,+)from e2b.sandbox.filesystem.filesystem import (- WriteInfo,EntryInfo,+ WriteEntry,+ WriteInfo,map_file_type,)from e2b.sandbox_sync.filesystem.watch_handle import WatchHandle+_FILESYSTEM_RPC_ERROR_MAP = {+ Code.not_found: FileNotFoundException,+}++_FILESYSTEM_HTTP_ERROR_MAP = {+ 404: FileNotFoundException,+}+++def _handle_filesystem_rpc_exception(e: Exception) -> Exception:+ return handle_rpc_exception(e, _FILESYSTEM_RPC_ERROR_MAP)+++def _handle_filesystem_envd_api_exception(r):+ return handle_envd_api_exception(r, _FILESYSTEM_HTTP_ERROR_MAP)++class Filesystem:"""Module for interacting with the filesystem in the sandbox.@@ -137,7 +160,7 @@ class Filesystem:timeout=self._connection_config.get_request_timeout(request_timeout),)- err = handle_envd_api_exception(r)+ err = _handle_filesystem_envd_api_exception(r)if err:raise err@@ -235,7 +258,7 @@ class Filesystem:timeout=self._connection_config.get_request_timeout(request_timeout),)- err = handle_envd_api_exception(r)+ err = _handle_filesystem_envd_api_exception(r)if err:raise err@@ -302,7 +325,7 @@ class Filesystem:return entriesexcept Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)def exists(self,@@ -333,7 +356,7 @@ class Filesystem:if isinstance(e, e2b_connect.ConnectException):if e.status == e2b_connect.Code.not_found:return False- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)def get_info(self,@@ -377,7 +400,7 @@ class Filesystem:),)except Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)def remove(self,@@ -401,7 +424,7 @@ class Filesystem:headers=authentication_header(self._envd_version, user),)except Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)def rename(self,@@ -450,7 +473,7 @@ class Filesystem:),)except Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)def make_dir(self,@@ -481,7 +504,7 @@ class Filesystem:if isinstance(e, e2b_connect.ConnectException):if e.status == e2b_connect.Code.already_exists:return False- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)def watch_dir(self,@@ -518,6 +541,6 @@ class Filesystem:},)except Exception as e:- raise handle_rpc_exception(e)+ raise _handle_filesystem_rpc_exception(e)return WatchHandle(self._rpc, r.watcher_id)diff --git a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.pyindex 3761730d4..8b340cc62 100644--- a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py+++ b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py@@ -29,8 +29,8 @@ from e2b.api.client.models import (from e2b.api.client.types import UNSETfrom e2b.connection_config import ApiParams, ConnectionConfigfrom e2b.exceptions import (- NotFoundException,SandboxException,+ SandboxNotFoundException,TemplateException,)from e2b.sandbox.main import SandboxBase@@ -92,7 +92,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Sandbox {sandbox_id} not found")if res.status_code >= 300:raise handle_api_exception(res)@@ -152,7 +152,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Sandbox {sandbox_id} not found")if res.status_code >= 300:raise handle_api_exception(res)@@ -304,7 +304,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Paused sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Paused sandbox {sandbox_id} not found")if res.status_code >= 300:raise handle_api_exception(res)@@ -333,7 +333,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Sandbox {sandbox_id} not found")if res.status_code >= 300:raise handle_api_exception(res)@@ -383,7 +383,7 @@ class SandboxApi(SandboxBase):)if res.status_code == 404:- raise NotFoundException(f"Sandbox {sandbox_id} not found")+ raise SandboxNotFoundException(f"Sandbox {sandbox_id} not found")if res.status_code == 409:return sandbox_iddiff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_info.py b/packages/python-sdk/tests/async/sandbox_async/files/test_info.pyindex 383643d77..7c9c51eb1 100644--- a/packages/python-sdk/tests/async/sandbox_async/files/test_info.py+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_info.py@@ -1,5 +1,5 @@import pytest-from e2b.exceptions import NotFoundException+from e2b.exceptions import FileNotFoundExceptionfrom e2b import AsyncSandbox, FileType@@ -26,7 +26,7 @@ async def test_get_info_of_file(async_sandbox: AsyncSandbox):async def test_get_info_of_nonexistent_file(async_sandbox: AsyncSandbox):filename = "test_does_not_exist.txt"- with pytest.raises(NotFoundException):+ with pytest.raises(FileNotFoundException):await async_sandbox.files.get_info(filename)@@ -53,7 +53,7 @@ async def test_get_info_of_directory(async_sandbox: AsyncSandbox):async def test_get_info_of_nonexistent_directory(async_sandbox: AsyncSandbox):dirname = "test_does_not_exist_dir"- with pytest.raises(NotFoundException):+ with pytest.raises(FileNotFoundException):await async_sandbox.files.get_info(dirname)diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_read.py b/packages/python-sdk/tests/async/sandbox_async/files/test_read.pyindex 5aec6b80d..6bb871e47 100644--- a/packages/python-sdk/tests/async/sandbox_async/files/test_read.py+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_read.py@@ -1,6 +1,6 @@import pytest-from e2b import NotFoundException, AsyncSandbox+from e2b import FileNotFoundException, NotFoundException, AsyncSandboxasync def test_read_file(async_sandbox: AsyncSandbox):@@ -15,6 +15,15 @@ async def test_read_file(async_sandbox: AsyncSandbox):async def test_read_non_existing_file(async_sandbox: AsyncSandbox):filename = "non_existing_file.txt"+ with pytest.raises(FileNotFoundException):+ await async_sandbox.files.read(filename)+++async def test_read_non_existing_file_catches_with_deprecated_not_found_exception(+ async_sandbox: AsyncSandbox,+):+ filename = "non_existing_file.txt"+with pytest.raises(NotFoundException):await async_sandbox.files.read(filename)diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_rename.py b/packages/python-sdk/tests/async/sandbox_async/files/test_rename.pyindex 6238cf6d1..626b3a79e 100644--- a/packages/python-sdk/tests/async/sandbox_async/files/test_rename.py+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_rename.py@@ -1,6 +1,6 @@import pytest-from e2b import NotFoundException, AsyncSandbox+from e2b import FileNotFoundException, AsyncSandboxasync def test_rename_file(async_sandbox: AsyncSandbox):@@ -25,5 +25,5 @@ async def test_rename_non_existing_file(async_sandbox: AsyncSandbox):old_filename = "non_existing_file.txt"new_filename = "new_non_existing_file.txt"- with pytest.raises(NotFoundException):+ with pytest.raises(FileNotFoundException):await async_sandbox.files.rename(old_filename, new_filename)diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py b/packages/python-sdk/tests/async/sandbox_async/files/test_watch.pyindex fd0f2f0e4..7ee0e54bc 100644--- a/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py@@ -3,7 +3,7 @@ import pytestfrom asyncio import Eventfrom e2b import (- NotFoundException,+ FileNotFoundException,AsyncSandbox,FilesystemEvent,FilesystemEventType,@@ -102,7 +102,7 @@ async def test_watch_recursive_directory_after_nested_folder_addition(async def test_watch_non_existing_directory(async_sandbox: AsyncSandbox):dirname = "non_existing_watch_dir"- with pytest.raises(NotFoundException):+ with pytest.raises(FileNotFoundException):await async_sandbox.files.watch_dir(dirname, on_event=lambda e: None)diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_info.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_info.pyindex 35e18ac84..aec4783e0 100644--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_info.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_info.py@@ -1,5 +1,5 @@import pytest-from e2b.exceptions import NotFoundException+from e2b.exceptions import FileNotFoundExceptionfrom e2b import Sandbox, FileType@@ -24,7 +24,7 @@ def test_get_info_of_file(sandbox: Sandbox):def test_get_info_of_nonexistent_file(sandbox: Sandbox):filename = "test_does_not_exist.txt"- with pytest.raises(NotFoundException):+ with pytest.raises(FileNotFoundException):sandbox.files.get_info(filename)@@ -49,7 +49,7 @@ def test_get_info_of_directory(sandbox: Sandbox):def test_get_info_of_nonexistent_directory(sandbox: Sandbox):dirname = "test_does_not_exist_dir"- with pytest.raises(NotFoundException):+ with pytest.raises(FileNotFoundException):sandbox.files.get_info(dirname)diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_read.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_read.pyindex d889e806d..f5dc3a32e 100644--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_read.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_read.py@@ -1,5 +1,5 @@import pytest-from e2b import NotFoundException+from e2b import FileNotFoundException, NotFoundExceptiondef test_read_file(sandbox):@@ -14,6 +14,13 @@ def test_read_file(sandbox):def test_read_non_existing_file(sandbox):filename = "non_existing_file.txt"+ with pytest.raises(FileNotFoundException):+ sandbox.files.read(filename)+++def test_read_non_existing_file_catches_with_deprecated_not_found_exception(sandbox):+ filename = "non_existing_file.txt"+with pytest.raises(NotFoundException):sandbox.files.read(filename)diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_rename.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_rename.pyindex 1c763fb99..f534cb47e 100644--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_rename.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_rename.py@@ -1,5 +1,5 @@import pytest-from e2b import NotFoundException, Sandbox+from e2b import FileNotFoundException, Sandboxdef test_rename_file(sandbox: Sandbox):@@ -24,5 +24,5 @@ def test_rename_non_existing_file(sandbox):old_filename = "non_existing_file.txt"new_filename = "new_non_existing_file.txt"- with pytest.raises(NotFoundException):+ with pytest.raises(FileNotFoundException):sandbox.files.rename(old_filename, new_filename)diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.pyindex eedfa57aa..03a5d6c66 100644--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.py@@ -1,6 +1,6 @@import pytest-from e2b import NotFoundException, FilesystemEventType, Sandbox, SandboxException+from e2b import FileNotFoundException, FilesystemEventType, Sandbox, SandboxExceptiondef test_watch_directory_changes(sandbox: Sandbox):@@ -108,7 +108,7 @@ def test_watch_recursive_directory_after_nested_folder_addition(sandbox: Sandboxdef test_watch_non_existing_directory(sandbox: Sandbox):dirname = "non_existing_watch_dir"- with pytest.raises(NotFoundException):+ with pytest.raises(FileNotFoundException):sandbox.files.watch_dir(dirname)