fix: Use format='bytes' for reading binary files from E2B sandbox

Fixes the critical bug where binary files would fail to read because
files.read() defaults to text mode (UTF-8 decoding). Now explicitly
uses format='bytes' which returns a bytearray.
This commit is contained in:
Bentlybro
2026-02-12 11:29:43 +00:00
parent d46e5e6b6a
commit 4a8368887f

View File

@@ -651,10 +651,11 @@ class ClaudeCodeBlock(Block):
pass
elif is_binary:
try:
# Read binary file as bytes
content_bytes = await sandbox.files.read(file_path)
if isinstance(content_bytes, str):
content_bytes = content_bytes.encode("utf-8")
# Read binary file as bytes using format="bytes"
# This returns bytearray, avoiding UTF-8 decoding issues
content_bytes = await sandbox.files.read(
file_path, format="bytes"
)
# Base64 encode the binary content
content_b64 = base64.b64encode(content_bytes).decode(