Skip to content

armgit / E2B

Public Imported from GitHub
0

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

refactor(sdk): make octet-stream file upload opt-in via useOctetStream (#1296)

Mish Ushakov2c995d4494f8
diff --git a/.changeset/write-octet-stream-override.md b/.changeset/write-octet-stream-override.md
new file mode 100644
index 000000000..3165bc080
--- /dev/null
+++ b/.changeset/write-octet-stream-override.md
@@ -0,0 +1,6 @@
+---
+'@e2b/python-sdk': patch
+'e2b': patch
+---
+
+added opt-in `useOctetStream` / `use_octet_stream` option to sandbox file write; default is now `multipart/form-data` regardless of envd version
diff --git a/packages/js-sdk/src/sandbox/filesystem/index.ts b/packages/js-sdk/src/sandbox/filesystem/index.ts
index 2803cc8ce..e5d14f2b3 100644
--- a/packages/js-sdk/src/sandbox/filesystem/index.ts
+++ b/packages/js-sdk/src/sandbox/filesystem/index.ts
@@ -172,6 +172,13 @@ export interface FilesystemWriteOpts extends FilesystemRequestOpts {
* When true, the upload will be gzip-compressed.
*/
gzip?: boolean
+ /**
+ * When true, the upload uses `application/octet-stream` instead of `multipart/form-data`.
+ *
+ * Defaults to `false`. Requires envd 0.5.7 or later — when not supported by
+ * the sandbox's envd version, the upload falls back to `multipart/form-data`.
+ */
+ useOctetStream?: boolean
}
/**
@@ -415,8 +422,10 @@ export class Filesystem {
user = defaultUsername
}
- const useOctetStream =
+ const supportsOctetStream =
compareVersions(this.envdApi.version, ENVD_OCTET_STREAM_UPLOAD) >= 0
+ const useOctetStream =
+ (writeOpts?.useOctetStream ?? false) && supportsOctetStream
const results: WriteInfo[] = []
diff --git a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
index 5b9f19a15..309f4f616 100644
--- a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
@@ -197,6 +197,7 @@ class Filesystem:
user: Optional[Username] = None,
request_timeout: Optional[float] = None,
gzip: bool = False,
+ use_octet_stream: bool = False,
) -> WriteInfo:
"""
Write content to a file on the path.
@@ -209,6 +210,7 @@ class Filesystem:
:param user: Run the operation as this user
:param request_timeout: Timeout for the request in **seconds**
:param gzip: Use gzip compression for the request
+ :param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later — when not supported, the upload falls back to `multipart/form-data`.
:return: Information about the written file
"""
@@ -217,6 +219,7 @@ class Filesystem:
user,
request_timeout,
gzip,
+ use_octet_stream,
)
if len(result) != 1:
@@ -230,6 +233,7 @@ class Filesystem:
user: Optional[Username] = None,
request_timeout: Optional[float] = None,
gzip: bool = False,
+ use_octet_stream: bool = False,
) -> List[WriteInfo]:
"""
Writes multiple files.
@@ -243,6 +247,7 @@ class Filesystem:
:param user: Run the operation as this user
:param request_timeout: Timeout for the request
:param gzip: Use gzip compression for the request
+ :param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later — when not supported, the upload falls back to `multipart/form-data`.
:return: Information about the written files
"""
username = user
@@ -252,7 +257,8 @@ class Filesystem:
if len(files) == 0:
return []
- use_octet_stream = self._envd_version >= ENVD_OCTET_STREAM_UPLOAD
+ supports_octet_stream = self._envd_version >= ENVD_OCTET_STREAM_UPLOAD
+ use_octet_stream = use_octet_stream and supports_octet_stream
results: List[WriteInfo] = []
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
index 8a5bc0aa8..b145200e4 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
@@ -195,6 +195,7 @@ class Filesystem:
user: Optional[Username] = None,
request_timeout: Optional[float] = None,
gzip: bool = False,
+ use_octet_stream: bool = False,
) -> WriteInfo:
"""
Write content to a file on the path.
@@ -207,6 +208,7 @@ class Filesystem:
:param user: Run the operation as this user
:param request_timeout: Timeout for the request in **seconds**
:param gzip: Use gzip compression for the request
+ :param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later — when not supported, the upload falls back to `multipart/form-data`.
:return: Information about the written file
"""
@@ -215,6 +217,7 @@ class Filesystem:
user=user,
request_timeout=request_timeout,
gzip=gzip,
+ use_octet_stream=use_octet_stream,
)
if len(result) != 1:
@@ -228,6 +231,7 @@ class Filesystem:
user: Optional[Username] = None,
request_timeout: Optional[float] = None,
gzip: bool = False,
+ use_octet_stream: bool = False,
) -> List[WriteInfo]:
"""
Writes a list of files to the filesystem.
@@ -239,6 +243,7 @@ class Filesystem:
:param user: Run the operation as this user
:param request_timeout: Timeout for the request
:param gzip: Use gzip compression for the request
+ :param use_octet_stream: Upload using `application/octet-stream` instead of `multipart/form-data`. Defaults to `False`. Requires envd 0.5.7 or later — when not supported, the upload falls back to `multipart/form-data`.
:return: Information about the written files
"""
username = user
@@ -248,7 +253,8 @@ class Filesystem:
if len(files) == 0:
return []
- use_octet_stream = self._envd_version >= ENVD_OCTET_STREAM_UPLOAD
+ supports_octet_stream = self._envd_version >= ENVD_OCTET_STREAM_UPLOAD
+ use_octet_stream = use_octet_stream and supports_octet_stream
results: List[WriteInfo] = []