Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
merge beta
0div68ac0383df4b
diff --cc packages/js-sdk/src/index.tsindex fdc292238,7491d0f45..bfd1b6cca--- a/packages/js-sdk/src/index.ts+++ b/packages/js-sdk/src/index.ts@@@ -1,26 -1,48 +1,34 @@@export { ApiClient } from './api'export type { components, paths } from './api'+export { ConnectionConfig } from './connectionConfig'+export type { ConnectionOpts, Username } from './connectionConfig'- export { AuthenticationError, InvalidArgumentError, NotEnoughSpaceError, NotFoundError, SandboxError, TemplateError, TimeoutError } from './errors'+ export {+ AuthenticationError,- SandboxError,- TimeoutError,- NotFoundError,- NotEnoughSpaceError,+ InvalidArgumentError,++ NotEnoughSpaceError,++ NotFoundError,++ SandboxError,+ TemplateError,++ TimeoutError,+ } from './errors'-export { ConnectionConfig } from './connectionConfig'export type { Logger } from './logs'-export type { ConnectionOpts, Username } from './connectionConfig'-export { FilesystemEventType } from './sandbox/filesystem/watchHandle'-export type {- FilesystemEvent,- WatchHandle,-} from './sandbox/filesystem/watchHandle'-export type { EntryInfo, Filesystem, WatchOpts } from './sandbox/filesystem'export { FileType } from './sandbox/filesystem'+export type { EntryInfo, Filesystem, WriteData } from './sandbox/filesystem'+export { FilesystemEventType } from './sandbox/filesystem/watchHandle'+export type { FilesystemEvent, WatchHandle } from './sandbox/filesystem/watchHandle'export { ProcessExitError } from './sandbox/process/processHandle'-export type {- ProcessResult,- Stdout,- Stderr,- PtyOutput,- ProcessHandle,-} from './sandbox/process/processHandle'+export type { ProcessHandle, ProcessResult, PtyOutput, Stderr, Stdout } from './sandbox/process/processHandle'export type { SandboxApiOpts } from './sandbox/sandboxApi'-export type {- ProcessInfo,- ProcessRequestOpts,- ProcessConnectOpts,- ProcessStartOpts,- Process,- Pty,-} from './sandbox/process'+export type { Process, ProcessConnectOpts, ProcessInfo, ProcessRequestOpts, ProcessStartOpts } from './sandbox/process'++export type { Pty } from './sandbox/pty'-export type { SandboxInfo } from './sandbox/sandboxApi'export type { SandboxOpts } from './sandbox'-import { Sandbox } from './sandbox'+export type { SandboxInfo } from './sandbox/sandboxApi'export { Sandbox }+import { Sandbox } from './sandbox'export default Sandboxdiff --cc packages/js-sdk/src/sandbox/filesystem/index.tsindex 030e8b804,df505d073..b71ab6184--- a/packages/js-sdk/src/sandbox/filesystem/index.ts+++ b/packages/js-sdk/src/sandbox/filesystem/index.ts@@@ -1,23 -1,31 +1,26 @@@-import {- createPromiseClient,- Transport,- PromiseClient,- ConnectError,- Code,-} from '@connectrpc/connect'+import { Code, ConnectError, createPromiseClient, PromiseClient, Transport } from '@connectrpc/connect'import {ConnectionConfig,- defaultUsername,- Username,ConnectionOpts,- KEEPALIVE_PING_INTERVAL_SEC,+ defaultUsername,KEEPALIVE_PING_HEADER,+ KEEPALIVE_PING_INTERVAL_SEC,+ Username,} from '../../connectionConfig'- import { handleEnvdApiError } from '../../envd/api'+ import { handleEnvdApiError, handleWatchDirStartEvent } from '../../envd/api'import { authenticationHeader, handleRpcError } from '../../envd/rpc'import { EnvdApiClient } from '../../envd/api'import { Filesystem as FilesystemService } from '../../envd/filesystem/filesystem_connect'-import { FileType as FsFileType } from '../../envd/filesystem/filesystem_pb'+import { EntryInfo, FileType as FsFileType } from '../../envd/filesystem/filesystem_pb'- import { FilesystemEvent, WatchHandle } from './watchHandle'-import { WatchHandle, FilesystemEvent } from './watchHandle'+import { clearTimeout } from 'timers'++import { FilesystemEvent, WatchHandle } from './watchHandle'+ /**+ * Information about a filesystem object.+ */export interface EntryInfo {name: stringtype?: FileType@@@ -40,7 -49,11 +46,10 @@@ function mapFileType(fileType: FsFileTy}}+ /**+ * Options for sending a request to the filesystem.+ */-export interface FilesystemRequestOpts- extends Partial<Pick<ConnectionOpts, 'requestTimeoutMs'>> {+export interface FilesystemRequestOpts extends Partial<Pick<ConnectionOpts, 'requestTimeoutMs'>> {user?: Username}@@@ -62,13 -81,35 +77,23 @@@ export class Filesystemthis.rpc = createPromiseClient(FilesystemService, transport)}+ /**+ * Reads a whole file content and returns it in requested format (text by default).+ *+ * @param path Path to the file+ * @param opts Options for the request+ * @param {format} [opts.format] Format of the file content. Default is 'text'.+ * @returns File content in requested format+ */- async read(- path: string,- opts?: FilesystemRequestOpts & { format?: 'text' }- ): Promise<string>- async read(- path: string,- opts?: FilesystemRequestOpts & { format: 'bytes' }- ): Promise<Uint8Array>- async read(- path: string,- opts?: FilesystemRequestOpts & { format: 'blob' }- ): Promise<Blob>- async read(- path: string,- opts?: FilesystemRequestOpts & { format: 'stream' }- ): Promise<ReadableStream<Uint8Array>>+ async read(path: string, opts?: FilesystemRequestOpts & { format?: 'text' }): Promise<string>+ async read(path: string, opts?: FilesystemRequestOpts & { format: 'bytes' }): Promise<Uint8Array>+ async read(path: string, opts?: FilesystemRequestOpts & { format: 'blob' }): Promise<Blob>+ async read(path: string, opts?: FilesystemRequestOpts & { format: 'stream' }): Promise<ReadableStream<Uint8Array>>async read(path: string,- opts?: FilesystemRequestOpts & { format?: 'text' | 'stream' | 'bytes' | 'blob' }+ opts?: FilesystemRequestOpts & {+ format?: 'text' | 'stream' | 'bytes' | 'blob'+ }): Promise<unknown> {const format = opts?.format ?? 'text'@@@ -145,9 -187,16 +175,16 @@@throw new Error('Expected to receive information about written file')}- return files[0] as EntryInfo+ return files.length === 1 && path ? (files[0] as EntryInfo) : (files as EntryInfo[])}+ /**+ * Lists entries in a directory.+ *+ * @param path Path to the directory+ * @param opts Options for the request+ * @returns List of entries in the directory+ */async list(path: string, opts?: FilesystemRequestOpts): Promise<EntryInfo[]> {try {const res = await this.rpc.listDir(@@@ -200,7 -256,19 +244,15 @@@}}+ /**+ * Renames a file or directory from one path to another.+ *+ * @param oldPath Path to the file or directory to move+ * @param newPath Path to move the file or directory to+ * @param opts Options for the request+ * @returns Information about the moved object+ */- async rename(- oldPath: string,- newPath: string,- opts?: FilesystemRequestOpts- ): Promise<EntryInfo> {+ async rename(oldPath: string, newPath: string, opts?: FilesystemRequestOpts): Promise<EntryInfo> {try {const res = await this.rpc.move({diff --cc packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.pyindex b7bfca494,0813176e2..7af797ba9--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py@@@ -100,57 -110,20 +112,75 @@@ class Filesystemuser: Username = "user",request_timeout: Optional[float] = None,) -> EntryInfo:- """Write to file"""+ """+ Writes content to a file on the path.+ When writing to a file that doesn't exist, the file will get created.+ When writing to a file that already exists, the file will get overwritten.+ When writing to a file that's in a directory that doesn't exist, you'll get an error.++ :param path: Path to the file+ :param data: Data to write to the file+ :param user: Run the operation as this user+ :param request_timeout: Timeout for the request+ :return: Information about the written file+ """- if isinstance(data, TextIOBase):- data = data.read().encode()++ @overload+ def write(+ self,+ files: List[WriteEntry],+ user: Optional[Username] = "user",- path: Optional[str] = None,+ request_timeout: Optional[float] = None,+ ) -> List[EntryInfo]:- """Write multiple files"""++ """++ Writes multiple files.++++ :param files: list of files to write++ :param user: Run the operation as this user++ :param request_timeout: Timeout for the request++ :return: Information about the written files++ """++ def write(+ self,+ path_or_files: str | List[WriteEntry],+ data_or_user: WriteData | Username = "user",+ user_or_request_timeout: Optional[float | Username] = None,+ request_timeout_or_none: Optional[float] = None+ ) -> EntryInfo | List[EntryInfo]:- """Write to file(s)++ """++ Writes content to a file on the path.+ When writing to a file that doesn't exist, the file will get created.+ When writing to a file that already exists, the file will get overwritten.+ When writing to a file that's in a directory that doesn't exist, you'll get an error.+ """++ path, write_files, user, request_timeout, = None, [], "user", None+ if isinstance(path_or_files, str):+ if isinstance(data_or_user, list):+ raise Exception("Cannot specify path with array of files")+ path, write_files, user, request_timeout = \+ path_or_files, [{"path": path_or_files, "data": data_or_user}], user_or_request_timeout or "user", request_timeout_or_none+ else:+ path, write_files, user, request_timeout = \+ None, path_or_files, data_or_user, user_or_request_timeout++ if len(write_files) == 0:+ raise Exception("Need at least one file to write")++ # Prepare the files for the multipart/form-data request+ httpx_files = []+ for file in write_files:+ file_path, file_data = file['path'], file['data']+ if isinstance(file_data, str) or isinstance(file_data, bytes):+ httpx_files.append(('file', (file_path, file_data)))+ elif isinstance(file_data, TextIOBase):+ httpx_files.append(('file', (file_path, file_data.read())))+ else:+ raise ValueError(f"Unsupported data type for file {file_path}")++ params = {"username": user}+ if path is not None: params["path"] = pathr = self._envd_api.post(ENVD_API_FILES_ROUTE,