Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Get paths for filesystem operations from envd

Jakub Novak08fc1e4c8aab
diff --git a/packages/js-sdk/src/envd/filesystem/filesystem_pb.ts b/packages/js-sdk/src/envd/filesystem/filesystem_pb.ts
index 3916a449d..b59608077 100644
--- a/packages/js-sdk/src/envd/filesystem/filesystem_pb.ts
+++ b/packages/js-sdk/src/envd/filesystem/filesystem_pb.ts
@@ -1,4 +1,4 @@
-// @generated by protoc-gen-es v1.9.0 with parameter "target=ts"
+// @generated by protoc-gen-es v1.10.0 with parameter "target=ts"
// @generated from file filesystem/filesystem.proto (package filesystem, syntax proto3)
/* eslint-disable */
// @ts-nocheck
@@ -123,6 +123,11 @@ export class MoveRequest extends Message<MoveRequest> {
* @generated from message filesystem.MoveResponse
*/
export class MoveResponse extends Message<MoveResponse> {
+ /**
+ * @generated from field: filesystem.EntryInfo entry = 1;
+ */
+ entry?: EntryInfo;
+
constructor(data?: PartialMessage<MoveResponse>) {
super();
proto3.util.initPartial(data, this);
@@ -131,6 +136,7 @@ export class MoveResponse extends Message<MoveResponse> {
static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "filesystem.MoveResponse";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
+ { no: 1, name: "entry", kind: "message", T: EntryInfo },
]);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MoveResponse {
@@ -191,6 +197,11 @@ export class MakeDirRequest extends Message<MakeDirRequest> {
* @generated from message filesystem.MakeDirResponse
*/
export class MakeDirResponse extends Message<MakeDirResponse> {
+ /**
+ * @generated from field: filesystem.EntryInfo entry = 1;
+ */
+ entry?: EntryInfo;
+
constructor(data?: PartialMessage<MakeDirResponse>) {
super();
proto3.util.initPartial(data, this);
@@ -199,6 +210,7 @@ export class MakeDirResponse extends Message<MakeDirResponse> {
static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "filesystem.MakeDirResponse";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
+ { no: 1, name: "entry", kind: "message", T: EntryInfo },
]);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MakeDirResponse {
@@ -259,6 +271,11 @@ export class RemoveRequest extends Message<RemoveRequest> {
* @generated from message filesystem.RemoveResponse
*/
export class RemoveResponse extends Message<RemoveResponse> {
+ /**
+ * @generated from field: filesystem.EntryInfo entry = 1;
+ */
+ entry?: EntryInfo;
+
constructor(data?: PartialMessage<RemoveResponse>) {
super();
proto3.util.initPartial(data, this);
@@ -267,6 +284,7 @@ export class RemoveResponse extends Message<RemoveResponse> {
static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "filesystem.RemoveResponse";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
+ { no: 1, name: "entry", kind: "message", T: EntryInfo },
]);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): RemoveResponse {
@@ -374,6 +392,11 @@ export class EntryInfo extends Message<EntryInfo> {
*/
type = FileType.UNSPECIFIED;
+ /**
+ * @generated from field: string path = 3;
+ */
+ path = "";
+
constructor(data?: PartialMessage<EntryInfo>) {
super();
proto3.util.initPartial(data, this);
@@ -384,6 +407,7 @@ export class EntryInfo extends Message<EntryInfo> {
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "type", kind: "enum", T: proto3.getEnumType(FileType) },
+ { no: 3, name: "path", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): EntryInfo {
diff --git a/packages/js-sdk/src/envd/process/process_pb.ts b/packages/js-sdk/src/envd/process/process_pb.ts
index f1205a9a5..5effe5c8e 100644
--- a/packages/js-sdk/src/envd/process/process_pb.ts
+++ b/packages/js-sdk/src/envd/process/process_pb.ts
@@ -1,4 +1,4 @@
-// @generated by protoc-gen-es v1.9.0 with parameter "target=ts"
+// @generated by protoc-gen-es v1.10.0 with parameter "target=ts"
// @generated from file process/process.proto (package process, syntax proto3)
/* eslint-disable */
// @ts-nocheck
diff --git a/packages/js-sdk/src/envd/schema.gen.ts b/packages/js-sdk/src/envd/schema.gen.ts
index cc5d9e207..d056472ed 100644
--- a/packages/js-sdk/src/envd/schema.gen.ts
+++ b/packages/js-sdk/src/envd/schema.gen.ts
@@ -3,114 +3,136 @@
* Do not make direct changes to the file.
*/
+
export interface paths {
- "/health": {
- get: {
- responses: {
- /** The service is healthy */
- 204: never;
- };
- };
- };
- "/sync": {
- post: {
- responses: {
- /** The time and metadata is synced with the host */
- 204: never;
- };
- };
- };
"/files": {
+ /** Download a file */
get: {
parameters: {
query: {
- /** Path to the file, URL encoded. Can be relative to user's home directory. */
path?: components["parameters"]["FilePath"];
- /** User used for setting the owner, or resolving relative paths. */
username: components["parameters"]["User"];
};
};
responses: {
200: components["responses"]["DownloadSuccess"];
- 400: components["responses"]["DirectoryPathError"];
+ 400: components["responses"]["InvalidPath"];
401: components["responses"]["InvalidUser"];
404: components["responses"]["FileNotFound"];
500: components["responses"]["InternalServerError"];
};
};
+ /** Upload a file and ensure the parent directories exist. If the file exists, it will be overwritten. */
post: {
parameters: {
query: {
- /** Path to the file, URL encoded. Can be relative to user's home directory. */
path?: components["parameters"]["FilePath"];
- /** User used for setting the owner, or resolving relative paths. */
username: components["parameters"]["User"];
};
};
+ requestBody: components["requestBodies"]["File"];
responses: {
- 204: components["responses"]["UploadSuccess"];
- 400: components["responses"]["DirectoryPathError"];
+ 200: components["responses"]["UploadSuccess"];
+ 400: components["responses"]["InvalidPath"];
401: components["responses"]["InvalidUser"];
500: components["responses"]["InternalServerError"];
507: components["responses"]["NotEnoughDiskSpace"];
};
- requestBody: components["requestBodies"]["File"];
+ };
+ };
+ "/health": {
+ /** Check the health of the service */
+ get: {
+ responses: {
+ /** @description The service is healthy */
+ 204: {
+ content: never;
+ };
+ };
+ };
+ };
+ "/sync": {
+ /** Ensure the time and metadata is synced with the host */
+ post: {
+ responses: {
+ /** @description The time and metadata is synced with the host */
+ 204: {
+ content: never;
+ };
+ };
};
};
}
+export type webhooks = Record<string, never>;
+
export interface components {
schemas: {
+ EntryInfo: {
+ /** @description Name of the file */
+ name: string;
+ /** @description Path to the file */
+ path: string;
+ /**
+ * @description Type of the file
+ * @enum {string}
+ */
+ type: "file" | "directory" | "unspecified";
+ };
Error: {
- /** @description Error message */
- message: string;
/** @description Error code */
code: number;
+ /** @description Error message */
+ message: string;
};
};
responses: {
- /** The file was uploaded successfully. */
- UploadSuccess: unknown;
- /** Entire file downloaded successfully. */
+ /** @description Entire file downloaded successfully. */
DownloadSuccess: {
content: {
"application/octet-stream": string;
};
};
- /** Directory path error */
- DirectoryPathError: {
+ /** @description File not found */
+ FileNotFound: {
content: {
"application/json": components["schemas"]["Error"];
};
};
- /** Internal server error */
+ /** @description Internal server error */
InternalServerError: {
content: {
"application/json": components["schemas"]["Error"];
};
};
- /** File not found */
- FileNotFound: {
+ /** @description Invalid path */
+ InvalidPath: {
content: {
"application/json": components["schemas"]["Error"];
};
};
- /** Invalid user */
+ /** @description Invalid user */
InvalidUser: {
content: {
"application/json": components["schemas"]["Error"];
};
};
- /** Not enough disk space */
+ /** @description Not enough disk space */
NotEnoughDiskSpace: {
content: {
"application/json": components["schemas"]["Error"];
};
};
+ /** @description The file was uploaded successfully. */
+ UploadSuccess: {
+ content: {
+ "application/json": components["schemas"]["EntryInfo"][];
+ };
+ };
};
parameters: {
/** @description Path to the file, URL encoded. Can be relative to user's home directory. */
- FilePath: string;
+ FilePath?: string;
/** @description User used for setting the owner, or resolving relative paths. */
User: string;
};
@@ -124,8 +146,12 @@ export interface components {
};
};
};
+ headers: never;
+ pathItems: never;
}
-export interface operations {}
+export type $defs = Record<string, never>;
+
+export type external = Record<string, never>;
-export interface external {}
+export type operations = Record<string, never>;
diff --git a/packages/js-sdk/src/sandbox/filesystem/index.ts b/packages/js-sdk/src/sandbox/filesystem/index.ts
index a1fa40436..cd784e3c8 100644
--- a/packages/js-sdk/src/sandbox/filesystem/index.ts
+++ b/packages/js-sdk/src/sandbox/filesystem/index.ts
@@ -5,7 +5,6 @@ import {
ConnectError,
Code,
} from '@connectrpc/connect'
-
import {
ConnectionConfig,
defaultUsername,
@@ -27,6 +26,7 @@ import { WatchHandle, FilesystemEvent } from './watchHandle'
export interface EntryInfo {
name: string
type: FileType
+ path: string
}
export const enum FileType {
@@ -95,7 +95,7 @@ export class Filesystem {
return res.data
}
- async write(path: string, data: string | ArrayBuffer | Blob | ReadableStream, opts?: FilesystemRequestOpts): Promise<void> {
+ async write(path: string, data: string | ArrayBuffer | Blob | ReadableStream, opts?: FilesystemRequestOpts): Promise<EntryInfo> {
const blob = await new Response(data).blob()
const res = await this.envdApi.api.POST('/files', {
@@ -120,6 +120,17 @@ export class Filesystem {
if (err) {
throw err
}
+
+ const files = res.data
+ if (!files || files.length === 0) {
+ throw new SandboxError('Write response did not contain required information')
+ }
+
+ return {
+ name: files[0].name,
+ type: FileType.FILE,
+ path: files[0].path,
+ }
}
async list(path: string, opts?: FilesystemRequestOpts): Promise<EntryInfo[]> {
@@ -138,6 +149,7 @@ export class Filesystem {
entries.push({
name: e.name,
type,
+ path: e.path,
})
}
}
@@ -167,26 +179,49 @@ export class Filesystem {
}
}
- async rename(oldPath: string, newPath: string, opts?: FilesystemRequestOpts): Promise<void> {
+ async rename(oldPath: string, newPath: string, opts?: FilesystemRequestOpts): Promise<EntryInfo> {
try {
- await this.rpc.move({
+ const res = await this.rpc.move({
source: oldPath,
destination: newPath,
}, {
headers: authenticationHeader(opts?.user),
signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),
})
+
+ const entry = res.entry
+ if (!entry) {
+ throw new SandboxError('Move response did not contain required information')
+ }
+
+ return {
+ name: entry.name,
+ type: mapFileType(entry.type)!,
+ path: entry.path,
+ }
} catch (err) {
throw handleRpcError(err)
}
}
- async remove(path: string, opts?: FilesystemRequestOpts): Promise<void> {
+ async remove(path: string, opts?: FilesystemRequestOpts): Promise<EntryInfo> {
try {
- await this.rpc.remove({ path }, {
+ const res = await this.rpc.remove({ path }, {
headers: authenticationHeader(opts?.user),
signal: this.connectionConfig.getSignal(opts?.requestTimeoutMs),
})
+
+ const entry = res.entry
+
+ if (!entry) {
+ throw new SandboxError('Remove response did not contain required information')
+ }
+
+ return {
+ path: entry.path,
+ name: entry.name,
+ type: mapFileType(entry.type)!,
+ }
} catch (err) {
throw handleRpcError(err)
}
diff --git a/packages/js-sdk/tests/sandbox/files/list.test.ts b/packages/js-sdk/tests/sandbox/files/list.test.ts
index 7422c1355..93f70c76a 100644
--- a/packages/js-sdk/tests/sandbox/files/list.test.ts
+++ b/packages/js-sdk/tests/sandbox/files/list.test.ts
@@ -16,6 +16,7 @@ sandboxTest('list directory', async ({ sandbox }) => {
assert.equal(files1.length, 1)
assert.equal(files1[0].name, 'test_file')
assert.equal(files1[0].type, 'file')
+ assert.equal(files1[0].path, `/home/user/${dirName}/test_file`)
const exists = await sandbox.files.exists(dirName)
assert.isTrue(exists)
diff --git a/packages/js-sdk/tests/sandbox/files/remove.test.ts b/packages/js-sdk/tests/sandbox/files/remove.test.ts
index ef760d025..0b6ed41a8 100644
--- a/packages/js-sdk/tests/sandbox/files/remove.test.ts
+++ b/packages/js-sdk/tests/sandbox/files/remove.test.ts
@@ -7,7 +7,11 @@ sandboxTest('remove file', async ({ sandbox }) => {
const content = 'This file will be removed.'
await sandbox.files.write(filename, content)
- await sandbox.files.remove(filename)
+ const info = await sandbox.files.remove(filename)
+ assert.equal(info.name, filename)
+ assert.equal(info.type, 'file')
+ assert.equal(info.path, `/home/user/${filename}`)
+
const exists = await sandbox.files.exists(filename)
assert.isFalse(exists)
})
diff --git a/packages/js-sdk/tests/sandbox/files/rename.test.ts b/packages/js-sdk/tests/sandbox/files/rename.test.ts
index 55354befb..1c23f7ccc 100644
--- a/packages/js-sdk/tests/sandbox/files/rename.test.ts
+++ b/packages/js-sdk/tests/sandbox/files/rename.test.ts
@@ -9,7 +9,11 @@ sandboxTest('rename file', async ({ sandbox }) => {
const content = 'This file will be renamed.'
await sandbox.files.write(oldFilename, content)
- await sandbox.files.rename(oldFilename, newFilename)
+ const info = await sandbox.files.rename(oldFilename, newFilename)
+ assert.equal(info.name, newFilename)
+ assert.equal(info.type, 'file')
+ assert.equal(info.path, `/home/user/${newFilename}`)
+
const existsOld = await sandbox.files.exists(oldFilename)
const existsNew = await sandbox.files.exists(newFilename)
assert.isFalse(existsOld)
diff --git a/packages/js-sdk/tests/sandbox/files/write.test.ts b/packages/js-sdk/tests/sandbox/files/write.test.ts
index b59e1626a..72d101d41 100644
--- a/packages/js-sdk/tests/sandbox/files/write.test.ts
+++ b/packages/js-sdk/tests/sandbox/files/write.test.ts
@@ -6,7 +6,11 @@ sandboxTest('write file', async ({ sandbox }) => {
const filename = 'test_write.txt'
const content = 'This is a test file.'
- await sandbox.files.write(filename, content)
+ const info = await sandbox.files.write(filename, content)
+ assert.equal(info.name, filename)
+ assert.equal(info.type, 'file')
+ assert.equal(info.path, `/home/user/${filename}`)
+
const exists = await sandbox.files.exists(filename)
assert.isTrue(exists)
const readContent = await sandbox.files.read(filename)
diff --git a/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.py b/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.py
index bfd24c5f2..ad928c1a2 100644
--- a/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.py
+++ b/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.py
@@ -1,12 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
+# NO CHECKED-IN PROTOBUF GENCODE
# source: filesystem/filesystem.proto
-# Protobuf Python Version: 5.26.1
+# Protobuf Python Version: 5.27.3
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
+from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
+_runtime_version.ValidateProtobufRuntimeVersion(
+ _runtime_version.Domain.PUBLIC,
+ 5,
+ 27,
+ 3,
+ '',
+ 'filesystem/filesystem.proto'
+)
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
@@ -14,7 +24,7 @@ _sym_db = _symbol_database.Default()
-DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1b\x66ilesystem/filesystem.proto\x12\nfilesystem\"G\n\x0bMoveRequest\x12\x16\n\x06source\x18\x01 \x01(\tR\x06source\x12 \n\x0b\x64\x65stination\x18\x02 \x01(\tR\x0b\x64\x65stination\"\x0e\n\x0cMoveResponse\"$\n\x0eMakeDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"\x11\n\x0fMakeDirResponse\"#\n\rRemoveRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"\x10\n\x0eRemoveResponse\"!\n\x0bStatRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\";\n\x0cStatResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry\"I\n\tEntryInfo\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12(\n\x04type\x18\x02 \x01(\x0e\x32\x14.filesystem.FileTypeR\x04type\"$\n\x0eListDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"B\n\x0fListDirResponse\x12/\n\x07\x65ntries\x18\x01 \x03(\x0b\x32\x15.filesystem.EntryInfoR\x07\x65ntries\"%\n\x0fWatchDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"\xe1\x02\n\x10WatchDirResponse\x12?\n\x05start\x18\x01 \x01(\x0b\x32\'.filesystem.WatchDirResponse.StartEventH\x00R\x05start\x12N\n\nfilesystem\x18\x02 \x01(\x0b\x32,.filesystem.WatchDirResponse.FilesystemEventH\x00R\nfilesystem\x12\x46\n\tkeepalive\x18\x03 \x01(\x0b\x32&.filesystem.WatchDirResponse.KeepAliveH\x00R\tkeepalive\x1a\x0c\n\nStartEvent\x1aP\n\x0f\x46ilesystemEvent\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12)\n\x04type\x18\x02 \x01(\x0e\x32\x15.filesystem.EventTypeR\x04type\x1a\x0b\n\tKeepAliveB\x07\n\x05\x65vent*R\n\x08\x46ileType\x12\x19\n\x15\x46ILE_TYPE_UNSPECIFIED\x10\x00\x12\x12\n\x0e\x46ILE_TYPE_FILE\x10\x01\x12\x17\n\x13\x46ILE_TYPE_DIRECTORY\x10\x02*\x98\x01\n\tEventType\x12\x1a\n\x16\x45VENT_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11\x45VENT_TYPE_CREATE\x10\x01\x12\x14\n\x10\x45VENT_TYPE_WRITE\x10\x02\x12\x15\n\x11\x45VENT_TYPE_REMOVE\x10\x03\x12\x15\n\x11\x45VENT_TYPE_RENAME\x10\x04\x12\x14\n\x10\x45VENT_TYPE_CHMOD\x10\x05\x32\x94\x03\n\nFilesystem\x12\x39\n\x04Stat\x12\x17.filesystem.StatRequest\x1a\x18.filesystem.StatResponse\x12\x42\n\x07MakeDir\x12\x1a.filesystem.MakeDirRequest\x1a\x1b.filesystem.MakeDirResponse\x12\x39\n\x04Move\x12\x17.filesystem.MoveRequest\x1a\x18.filesystem.MoveResponse\x12\x42\n\x07ListDir\x12\x1a.filesystem.ListDirRequest\x1a\x1b.filesystem.ListDirResponse\x12G\n\x08WatchDir\x12\x1b.filesystem.WatchDirRequest\x1a\x1c.filesystem.WatchDirResponse0\x01\x12?\n\x06Remove\x12\x19.filesystem.RemoveRequest\x1a\x1a.filesystem.RemoveResponseBi\n\x0e\x63om.filesystemB\x0f\x46ilesystemProtoP\x01\xa2\x02\x03\x46XX\xaa\x02\nFilesystem\xca\x02\nFilesystem\xe2\x02\x16\x46ilesystem\\GPBMetadata\xea\x02\nFilesystemb\x06proto3')
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1b\x66ilesystem/filesystem.proto\x12\nfilesystem\"G\n\x0bMoveRequest\x12\x16\n\x06source\x18\x01 \x01(\tR\x06source\x12 \n\x0b\x64\x65stination\x18\x02 \x01(\tR\x0b\x64\x65stination\";\n\x0cMoveResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry\"$\n\x0eMakeDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\">\n\x0fMakeDirResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry\"#\n\rRemoveRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"=\n\x0eRemoveResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry\"!\n\x0bStatRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\";\n\x0cStatResponse\x12+\n\x05\x65ntry\x18\x01 \x01(\x0b\x32\x15.filesystem.EntryInfoR\x05\x65ntry\"]\n\tEntryInfo\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12(\n\x04type\x18\x02 \x01(\x0e\x32\x14.filesystem.FileTypeR\x04type\x12\x12\n\x04path\x18\x03 \x01(\tR\x04path\"$\n\x0eListDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"B\n\x0fListDirResponse\x12/\n\x07\x65ntries\x18\x01 \x03(\x0b\x32\x15.filesystem.EntryInfoR\x07\x65ntries\"%\n\x0fWatchDirRequest\x12\x12\n\x04path\x18\x01 \x01(\tR\x04path\"\xe1\x02\n\x10WatchDirResponse\x12?\n\x05start\x18\x01 \x01(\x0b\x32\'.filesystem.WatchDirResponse.StartEventH\x00R\x05start\x12N\n\nfilesystem\x18\x02 \x01(\x0b\x32,.filesystem.WatchDirResponse.FilesystemEventH\x00R\nfilesystem\x12\x46\n\tkeepalive\x18\x03 \x01(\x0b\x32&.filesystem.WatchDirResponse.KeepAliveH\x00R\tkeepalive\x1a\x0c\n\nStartEvent\x1aP\n\x0f\x46ilesystemEvent\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12)\n\x04type\x18\x02 \x01(\x0e\x32\x15.filesystem.EventTypeR\x04type\x1a\x0b\n\tKeepAliveB\x07\n\x05\x65vent*R\n\x08\x46ileType\x12\x19\n\x15\x46ILE_TYPE_UNSPECIFIED\x10\x00\x12\x12\n\x0e\x46ILE_TYPE_FILE\x10\x01\x12\x17\n\x13\x46ILE_TYPE_DIRECTORY\x10\x02*\x98\x01\n\tEventType\x12\x1a\n\x16\x45VENT_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11\x45VENT_TYPE_CREATE\x10\x01\x12\x14\n\x10\x45VENT_TYPE_WRITE\x10\x02\x12\x15\n\x11\x45VENT_TYPE_REMOVE\x10\x03\x12\x15\n\x11\x45VENT_TYPE_RENAME\x10\x04\x12\x14\n\x10\x45VENT_TYPE_CHMOD\x10\x05\x32\x94\x03\n\nFilesystem\x12\x39\n\x04Stat\x12\x17.filesystem.StatRequest\x1a\x18.filesystem.StatResponse\x12\x42\n\x07MakeDir\x12\x1a.filesystem.MakeDirRequest\x1a\x1b.filesystem.MakeDirResponse\x12\x39\n\x04Move\x12\x17.filesystem.MoveRequest\x1a\x18.filesystem.MoveResponse\x12\x42\n\x07ListDir\x12\x1a.filesystem.ListDirRequest\x1a\x1b.filesystem.ListDirResponse\x12G\n\x08WatchDir\x12\x1b.filesystem.WatchDirRequest\x1a\x1c.filesystem.WatchDirResponse0\x01\x12?\n\x06Remove\x12\x19.filesystem.RemoveRequest\x1a\x1a.filesystem.RemoveResponseBi\n\x0e\x63om.filesystemB\x0f\x46ilesystemProtoP\x01\xa2\x02\x03\x46XX\xaa\x02\nFilesystem\xca\x02\nFilesystem\xe2\x02\x16\x46ilesystem\\GPBMetadata\xea\x02\nFilesystemb\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
@@ -22,42 +32,42 @@ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'filesystem.filesystem_pb2',
if not _descriptor._USE_C_DESCRIPTORS:
_globals['DESCRIPTOR']._loaded_options = None
_globals['DESCRIPTOR']._serialized_options = b'\n\016com.filesystemB\017FilesystemProtoP\001\242\002\003FXX\252\002\nFilesystem\312\002\nFilesystem\342\002\026Filesystem\\GPBMetadata\352\002\nFilesystem'
- _globals['_FILETYPE']._serialized_start=916
- _globals['_FILETYPE']._serialized_end=998
- _globals['_EVENTTYPE']._serialized_start=1001
- _globals['_EVENTTYPE']._serialized_end=1153
+ _globals['_FILETYPE']._serialized_start=1071
+ _globals['_FILETYPE']._serialized_end=1153
+ _globals['_EVENTTYPE']._serialized_start=1156
+ _globals['_EVENTTYPE']._serialized_end=1308
_globals['_MOVEREQUEST']._serialized_start=43
_globals['_MOVEREQUEST']._serialized_end=114
_globals['_MOVERESPONSE']._serialized_start=116
- _globals['_MOVERESPONSE']._serialized_end=130
- _globals['_MAKEDIRREQUEST']._serialized_start=132
- _globals['_MAKEDIRREQUEST']._serialized_end=168
- _globals['_MAKEDIRRESPONSE']._serialized_start=170
- _globals['_MAKEDIRRESPONSE']._serialized_end=187
- _globals['_REMOVEREQUEST']._serialized_start=189
- _globals['_REMOVEREQUEST']._serialized_end=224
- _globals['_REMOVERESPONSE']._serialized_start=226
- _globals['_REMOVERESPONSE']._serialized_end=242
- _globals['_STATREQUEST']._serialized_start=244
- _globals['_STATREQUEST']._serialized_end=277
- _globals['_STATRESPONSE']._serialized_start=279
- _globals['_STATRESPONSE']._serialized_end=338
- _globals['_ENTRYINFO']._serialized_start=340
- _globals['_ENTRYINFO']._serialized_end=413
- _globals['_LISTDIRREQUEST']._serialized_start=415
- _globals['_LISTDIRREQUEST']._serialized_end=451
- _globals['_LISTDIRRESPONSE']._serialized_start=453
- _globals['_LISTDIRRESPONSE']._serialized_end=519
- _globals['_WATCHDIRREQUEST']._serialized_start=521
- _globals['_WATCHDIRREQUEST']._serialized_end=558
- _globals['_WATCHDIRRESPONSE']._serialized_start=561
- _globals['_WATCHDIRRESPONSE']._serialized_end=914
- _globals['_WATCHDIRRESPONSE_STARTEVENT']._serialized_start=798
- _globals['_WATCHDIRRESPONSE_STARTEVENT']._serialized_end=810
- _globals['_WATCHDIRRESPONSE_FILESYSTEMEVENT']._serialized_start=812
- _globals['_WATCHDIRRESPONSE_FILESYSTEMEVENT']._serialized_end=892
- _globals['_WATCHDIRRESPONSE_KEEPALIVE']._serialized_start=894
- _globals['_WATCHDIRRESPONSE_KEEPALIVE']._serialized_end=905
- _globals['_FILESYSTEM']._serialized_start=1156
- _globals['_FILESYSTEM']._serialized_end=1560
+ _globals['_MOVERESPONSE']._serialized_end=175
+ _globals['_MAKEDIRREQUEST']._serialized_start=177
+ _globals['_MAKEDIRREQUEST']._serialized_end=213
+ _globals['_MAKEDIRRESPONSE']._serialized_start=215
+ _globals['_MAKEDIRRESPONSE']._serialized_end=277
+ _globals['_REMOVEREQUEST']._serialized_start=279
+ _globals['_REMOVEREQUEST']._serialized_end=314
+ _globals['_REMOVERESPONSE']._serialized_start=316
+ _globals['_REMOVERESPONSE']._serialized_end=377
+ _globals['_STATREQUEST']._serialized_start=379
+ _globals['_STATREQUEST']._serialized_end=412
+ _globals['_STATRESPONSE']._serialized_start=414
+ _globals['_STATRESPONSE']._serialized_end=473
+ _globals['_ENTRYINFO']._serialized_start=475
+ _globals['_ENTRYINFO']._serialized_end=568
+ _globals['_LISTDIRREQUEST']._serialized_start=570
+ _globals['_LISTDIRREQUEST']._serialized_end=606
+ _globals['_LISTDIRRESPONSE']._serialized_start=608
+ _globals['_LISTDIRRESPONSE']._serialized_end=674
+ _globals['_WATCHDIRREQUEST']._serialized_start=676
+ _globals['_WATCHDIRREQUEST']._serialized_end=713
+ _globals['_WATCHDIRRESPONSE']._serialized_start=716
+ _globals['_WATCHDIRRESPONSE']._serialized_end=1069
+ _globals['_WATCHDIRRESPONSE_STARTEVENT']._serialized_start=953
+ _globals['_WATCHDIRRESPONSE_STARTEVENT']._serialized_end=965
+ _globals['_WATCHDIRRESPONSE_FILESYSTEMEVENT']._serialized_start=967
+ _globals['_WATCHDIRRESPONSE_FILESYSTEMEVENT']._serialized_end=1047
+ _globals['_WATCHDIRRESPONSE_KEEPALIVE']._serialized_start=1049
+ _globals['_WATCHDIRRESPONSE_KEEPALIVE']._serialized_end=1060
+ _globals['_FILESYSTEM']._serialized_start=1311
+ _globals['_FILESYSTEM']._serialized_end=1715
# @@protoc_insertion_point(module_scope)
diff --git a/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.pyi b/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.pyi
index 5972b4714..c0ca2c7d1 100644
--- a/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.pyi
+++ b/packages/python-sdk/e2b/envd/filesystem/filesystem_pb2.pyi
@@ -39,8 +39,10 @@ class MoveRequest(_message.Message):
def __init__(self, source: _Optional[str] = ..., destination: _Optional[str] = ...) -> None: ...
class MoveResponse(_message.Message):
- __slots__ = ()
- def __init__(self) -> None: ...
+ __slots__ = ("entry",)
+ ENTRY_FIELD_NUMBER: _ClassVar[int]
+ entry: EntryInfo
+ def __init__(self, entry: _Optional[_Union[EntryInfo, _Mapping]] = ...) -> None: ...
class MakeDirRequest(_message.Message):
__slots__ = ("path",)
@@ -49,8 +51,10 @@ class MakeDirRequest(_message.Message):
def __init__(self, path: _Optional[str] = ...) -> None: ...
class MakeDirResponse(_message.Message):
- __slots__ = ()
- def __init__(self) -> None: ...
+ __slots__ = ("entry",)
+ ENTRY_FIELD_NUMBER: _ClassVar[int]
+ entry: EntryInfo
+ def __init__(self, entry: _Optional[_Union[EntryInfo, _Mapping]] = ...) -> None: ...
class RemoveRequest(_message.Message):
__slots__ = ("path",)
@@ -59,8 +63,10 @@ class RemoveRequest(_message.Message):
def __init__(self, path: _Optional[str] = ...) -> None: ...
class RemoveResponse(_message.Message):
- __slots__ = ()
- def __init__(self) -> None: ...
+ __slots__ = ("entry",)
+ ENTRY_FIELD_NUMBER: _ClassVar[int]
+ entry: EntryInfo
+ def __init__(self, entry: _Optional[_Union[EntryInfo, _Mapping]] = ...) -> None: ...
class StatRequest(_message.Message):
__slots__ = ("path",)
@@ -75,12 +81,14 @@ class StatResponse(_message.Message):
def __init__(self, entry: _Optional[_Union[EntryInfo, _Mapping]] = ...) -> None: ...
class EntryInfo(_message.Message):
- __slots__ = ("name", "type")
+ __slots__ = ("name", "type", "path")
NAME_FIELD_NUMBER: _ClassVar[int]
TYPE_FIELD_NUMBER: _ClassVar[int]
+ PATH_FIELD_NUMBER: _ClassVar[int]
name: str
type: FileType
- def __init__(self, name: _Optional[str] = ..., type: _Optional[_Union[FileType, str]] = ...) -> None: ...
+ path: str
+ def __init__(self, name: _Optional[str] = ..., type: _Optional[_Union[FileType, str]] = ..., path: _Optional[str] = ...) -> None: ...
class ListDirRequest(_message.Message):
__slots__ = ("path",)
diff --git a/packages/python-sdk/e2b/envd/process/process_pb2.py b/packages/python-sdk/e2b/envd/process/process_pb2.py
index 4b2ed2219..1d0e7c033 100644
--- a/packages/python-sdk/e2b/envd/process/process_pb2.py
+++ b/packages/python-sdk/e2b/envd/process/process_pb2.py
@@ -1,12 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
+# NO CHECKED-IN PROTOBUF GENCODE
# source: process/process.proto
-# Protobuf Python Version: 5.26.1
+# Protobuf Python Version: 5.27.3
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
+from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
+_runtime_version.ValidateProtobufRuntimeVersion(
+ _runtime_version.Domain.PUBLIC,
+ 5,
+ 27,
+ 3,
+ '',
+ 'process/process.proto'
+)
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
diff --git a/packages/python-sdk/e2b/sandbox/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox/filesystem/filesystem.py
index 61c77483b..41d1d81c3 100644
--- a/packages/python-sdk/e2b/sandbox/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox/filesystem/filesystem.py
@@ -20,3 +20,4 @@ def map_file_type(ft: filesystem_pb2.FileType):
class EntryInfo:
name: str
type: FileType
+ path: str
diff --git a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
index 64b2b0147..3050261af 100644
--- a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
@@ -9,7 +9,7 @@ from typing import (
overload,
Literal,
Union,
- IO,
+ BinaryIO,
)
from e2b.sandbox.filesystem.filesystem import EntryInfo, map_file_type
@@ -98,10 +98,10 @@ class Filesystem:
async def write(
self,
path: str,
- data: Union[str, bytes, IO],
+ data: Union[str, bytes, BinaryIO],
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> None:
+ ) -> EntryInfo:
r = await self._envd_api.post(
ENVD_API_FILES_ROUTE,
files={"file": data},
@@ -113,6 +113,8 @@ class Filesystem:
if err:
raise err
+ return EntryInfo(**r.json()[0])
+
async def list(
self,
path: str,
@@ -133,7 +135,7 @@ class Filesystem:
event_type = map_file_type(entry.type)
if event_type:
- entries.append(EntryInfo(name=entry.name, type=event_type))
+ entries.append(EntryInfo(name=entry.name, type=event_type, path=entry.path))
return entries
except Exception as e:
@@ -167,15 +169,16 @@ class Filesystem:
path: str,
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> None:
+ ) -> EntryInfo:
try:
- await self._rpc.aremove(
+ r = await self._rpc.aremove(
filesystem_pb2.RemoveRequest(path=path),
request_timeout=self._connection_config.get_request_timeout(
request_timeout
),
headers=authentication_header(user),
)
+ return r.entry
except Exception as e:
raise handle_rpc_exception(e)
@@ -185,9 +188,9 @@ class Filesystem:
new_path: str,
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> None:
+ ) -> EntryInfo:
try:
- await self._rpc.amove(
+ r = await self._rpc.amove(
filesystem_pb2.MoveRequest(
source=old_path,
destination=new_path,
@@ -197,6 +200,7 @@ class Filesystem:
),
headers=authentication_header(user),
)
+ return r.entry
except Exception as e:
raise handle_rpc_exception(e)
diff --git a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
index 0f9c829ce..bd016b214 100644
--- a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
@@ -74,6 +74,9 @@ class SandboxApi(SandboxApiBase):
request_timeout=request_timeout,
)
+ if config.debug:
+ return True
+
async with AsyncApiClient(config) as api_client:
res = await delete_sandboxes_sandbox_id.asyncio_detailed(
sandbox_id,
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
index 775d41f7e..e7424942d 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
@@ -104,7 +104,7 @@ class Filesystem:
data: Union[str, bytes, IO],
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> None:
+ ) -> EntryInfo:
r = self._envd_api.post(
ENVD_API_FILES_ROUTE,
files={"file": data},
@@ -116,6 +116,10 @@ class Filesystem:
if err:
raise err
+ data = r.json()
+
+ return EntryInfo(**data[0])
+
def list(
self,
path: str,
@@ -136,7 +140,7 @@ class Filesystem:
event_type = map_file_type(entry.type)
if event_type:
- entries.append(EntryInfo(name=entry.name, type=event_type))
+ entries.append(EntryInfo(name=entry.name, type=event_type, path=entry.path))
return entries
except Exception as e:
@@ -169,15 +173,17 @@ class Filesystem:
path: str,
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> None:
+ ) -> EntryInfo:
try:
- self._rpc.remove(
+ r = self._rpc.remove(
filesystem_pb2.RemoveRequest(path=path),
request_timeout=self._connection_config.get_request_timeout(
request_timeout
),
headers=authentication_header(user),
)
+
+ return r.entry
except Exception as e:
raise handle_rpc_exception(e)
@@ -187,9 +193,9 @@ class Filesystem:
new_path: str,
user: Username = "user",
request_timeout: Optional[float] = None,
- ) -> None:
+ ) -> EntryInfo:
try:
- self._rpc.move(
+ r = self._rpc.move(
filesystem_pb2.MoveRequest(
source=old_path,
destination=new_path,
@@ -199,6 +205,8 @@ class Filesystem:
),
headers=authentication_header(user),
)
+
+ return r.entry
except Exception as e:
raise handle_rpc_exception(e)
diff --git a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
index 945b46d92..b76c804ca 100644
--- a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
@@ -77,6 +77,9 @@ class SandboxApi(SandboxApiBase):
request_timeout=request_timeout,
)
+ if config.debug:
+ return True
+
with ApiClient(config, transport=cls._transport) as api_client:
res = delete_sandboxes_sandbox_id.sync_detailed(
sandbox_id,
diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_files_list.py b/packages/python-sdk/tests/async/sandbox_async/files/test_files_list.py
index a23959774..3ff1612f3 100644
--- a/packages/python-sdk/tests/async/sandbox_async/files/test_files_list.py
+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_files_list.py
@@ -1,5 +1,3 @@
-import pytest
-
from e2b import AsyncSandbox, FileType
@@ -12,6 +10,9 @@ async def test_list_directory(async_sandbox: AsyncSandbox):
await async_sandbox.files.write(f"{dir_name}/test_file", "test")
files1 = await async_sandbox.files.list(dir_name)
+ print(files1)
assert len(files1) == 1
+ print(files1[0])
assert files1[0].name == "test_file"
assert files1[0].type == FileType.FILE
+ assert files1[0].path == f"/home/user/{dir_name}/test_file"
diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_make_dir.py b/packages/python-sdk/tests/async/sandbox_async/files/test_make_dir.py
index a4d8ada97..3f5d57244 100644
--- a/packages/python-sdk/tests/async/sandbox_async/files/test_make_dir.py
+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_make_dir.py
@@ -1,5 +1,3 @@
-import pytest
-
from e2b import AsyncSandbox
@@ -11,6 +9,16 @@ async def test_make_directory(async_sandbox: AsyncSandbox):
assert exists
+async def test_make_directory_already_exists(async_sandbox: AsyncSandbox):
+ dir_name = "test_directory"
+
+ created = await async_sandbox.files.make_dir(dir_name)
+ assert created
+
+ created = await async_sandbox.files.make_dir(dir_name)
+ assert not created
+
+
async def test_make_nested_directory(async_sandbox: AsyncSandbox):
nested_dir_name = "test_directory/nested_directory"
diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_remove.py b/packages/python-sdk/tests/async/sandbox_async/files/test_remove.py
index b2f4c8fcd..a1c1d3125 100644
--- a/packages/python-sdk/tests/async/sandbox_async/files/test_remove.py
+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_remove.py
@@ -8,7 +8,8 @@ async def test_remove_file(async_sandbox: AsyncSandbox):
content = "This file will be removed."
await async_sandbox.files.write(filename, content)
- await async_sandbox.files.remove(filename)
+ info = await async_sandbox.files.remove(filename)
+ assert info.path == f"/home/user/{filename}"
exists = await async_sandbox.files.exists(filename)
assert not exists
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.py
index 3ab756261..6238cf6d1 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
@@ -9,11 +9,14 @@ async def test_rename_file(async_sandbox: AsyncSandbox):
content = "This file will be renamed."
await async_sandbox.files.write(old_filename, content)
- await async_sandbox.files.rename(old_filename, new_filename)
+ info = await async_sandbox.files.rename(old_filename, new_filename)
+ assert info.path == f"/home/user/{new_filename}"
+
exists_old = await async_sandbox.files.exists(old_filename)
exists_new = await async_sandbox.files.exists(new_filename)
assert not exists_old
assert exists_new
+
read_content = await async_sandbox.files.read(new_filename)
assert read_content == content
diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_write.py b/packages/python-sdk/tests/async/sandbox_async/files/test_write.py
index a942e96c3..bdfbf514a 100644
--- a/packages/python-sdk/tests/async/sandbox_async/files/test_write.py
+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_write.py
@@ -1,5 +1,3 @@
-import pytest
-
from e2b import AsyncSandbox
@@ -7,7 +5,9 @@ async def test_write_file(async_sandbox: AsyncSandbox):
filename = "test_write.txt"
content = "This is a test file."
- await async_sandbox.files.write(filename, content)
+ info = await async_sandbox.files.write(filename, content)
+ assert info.path == f"/home/user/{filename}"
+
exists = await async_sandbox.files.exists(filename)
assert exists
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_list_dir.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_list_dir.py
index 5c701b6b8..420aee529 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_list_dir.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_list_dir.py
@@ -13,3 +13,4 @@ def test_list_directory(sandbox: Sandbox):
assert len(files1) == 1
assert files1[0].name == "test_file"
assert files1[0].type == FileType.FILE
+ assert files1[0].path == f"/home/user/{dir_name}/test_file"
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_make_dir.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_make_dir.py
index ce37cbed4..698c961e4 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_make_dir.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_make_dir.py
@@ -1,4 +1,7 @@
-def test_make_directory(sandbox):
+from e2b import Sandbox
+
+
+def test_make_directory(sandbox: Sandbox):
dir_name = "test_directory"
sandbox.files.make_dir(dir_name)
@@ -6,7 +9,17 @@ def test_make_directory(sandbox):
assert exists
-def test_make_nested_directory(sandbox):
+async def test_make_directory_already_exists(sandbox: Sandbox):
+ dir_name = "test_directory"
+
+ created = sandbox.files.make_dir(dir_name)
+ assert created
+
+ created = sandbox.files.make_dir(dir_name)
+ assert not created
+
+
+def test_make_nested_directory(sandbox: Sandbox):
nested_dir_name = "test_directory/nested_directory"
sandbox.files.make_dir(nested_dir_name)
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_remove.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_remove.py
index 6e65a6d16..8f48af53d 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_remove.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_remove.py
@@ -1,9 +1,15 @@
-def test_remove_file(sandbox):
+from e2b import Sandbox
+
+
+def test_remove_file(sandbox: Sandbox):
filename = "test_remove.txt"
content = "This file will be removed."
sandbox.files.write(filename, content)
- sandbox.files.remove(filename)
+
+ info = sandbox.files.remove(filename)
+ assert info.path == f"/home/user/{filename}"
+
exists = sandbox.files.exists(filename)
assert not exists
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.py
index 1267a6842..1c763fb99 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,14 +1,17 @@
import pytest
-from e2b import NotFoundException
+from e2b import NotFoundException, Sandbox
-def test_rename_file(sandbox):
+def test_rename_file(sandbox: Sandbox):
old_filename = "test_rename_old.txt"
new_filename = "test_rename_new.txt"
content = "This file will be renamed."
sandbox.files.write(old_filename, content)
- sandbox.files.rename(old_filename, new_filename)
+
+ info = sandbox.files.rename(old_filename, new_filename)
+ assert info.path == f"/home/user/{new_filename}"
+
exists_old = sandbox.files.exists(old_filename)
exists_new = sandbox.files.exists(new_filename)
assert not exists_old
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
index 0aebddcc1..ba0390ee1 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
@@ -2,7 +2,9 @@ def test_write_file(sandbox):
filename = "test_write.txt"
content = "This is a test file."
- sandbox.files.write(filename, content)
+ info = sandbox.files.write(filename, content)
+ assert info.path == f"/home/user/{filename}"
+
exists = sandbox.files.exists(filename)
assert exists
diff --git a/spec/envd/envd.yaml b/spec/envd/envd.yaml
index ba36a4761..62cc5b9ea 100644
--- a/spec/envd/envd.yaml
+++ b/spec/envd/envd.yaml
@@ -35,7 +35,7 @@ paths:
"401":
$ref: "#/components/responses/InvalidUser"
"400":
- $ref: "#/components/responses/DirectoryPathError"
+ $ref: "#/components/responses/InvalidPath"
"404":
$ref: "#/components/responses/FileNotFound"
"500":
@@ -49,10 +49,10 @@ paths:
requestBody:
$ref: "#/components/requestBodies/File"
responses:
- "204":
+ "200":
$ref: "#/components/responses/UploadSuccess"
"400":
- $ref: "#/components/responses/DirectoryPathError"
+ $ref: "#/components/responses/InvalidPath"
"401":
$ref: "#/components/responses/InvalidUser"
"500":
@@ -93,6 +93,13 @@ components:
responses:
UploadSuccess:
description: The file was uploaded successfully.
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: "#/components/schemas/EntryInfo"
+
DownloadSuccess:
description: Entire file downloaded successfully.
content:
@@ -101,8 +108,8 @@ components:
type: string
format: binary
description: The file content
- DirectoryPathError:
- description: Directory path error
+ InvalidPath:
+ description: Invalid path
content:
application/json:
schema:
@@ -144,3 +151,22 @@ components:
code:
type: integer
description: Error code
+ EntryInfo:
+ required:
+ - path
+ - name
+ - type
+ properties:
+ path:
+ type: string
+ description: Path to the file
+ name:
+ type: string
+ description: Name of the file
+ type:
+ type: string
+ description: Type of the file
+ enum:
+ - file
+ - directory
+ - unspecified
diff --git a/spec/envd/filesystem/filesystem.proto b/spec/envd/filesystem/filesystem.proto
index 9695d8c5d..c1483100d 100644
--- a/spec/envd/filesystem/filesystem.proto
+++ b/spec/envd/filesystem/filesystem.proto
@@ -16,19 +16,25 @@ message MoveRequest {
string destination = 2;
}
-message MoveResponse {}
+message MoveResponse {
+ EntryInfo entry = 1;
+}
message MakeDirRequest {
string path = 1;
}
-message MakeDirResponse {}
+message MakeDirResponse {
+ EntryInfo entry = 1;
+}
message RemoveRequest {
string path = 1;
}
-message RemoveResponse {}
+message RemoveResponse {
+ EntryInfo entry = 1;
+}
message StatRequest {
string path = 1;
@@ -41,6 +47,7 @@ message StatResponse {
message EntryInfo {
string name = 1;
FileType type = 2;
+ string path = 3;
}
enum FileType {