From 4a8368887f8188383c59ee7b651ffbb1fca405f8 Mon Sep 17 00:00:00 2001 From: Bentlybro Date: Thu, 12 Feb 2026 11:29:43 +0000 Subject: [PATCH] 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. --- autogpt_platform/backend/backend/blocks/claude_code.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/autogpt_platform/backend/backend/blocks/claude_code.py b/autogpt_platform/backend/backend/blocks/claude_code.py index c9bb9aa0de..12b7ac349b 100644 --- a/autogpt_platform/backend/backend/blocks/claude_code.py +++ b/autogpt_platform/backend/backend/blocks/claude_code.py @@ -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(