write file with sandbox raise string format error: KeyError: 'e' #311

Closed
opened 2026-02-16 09:15:20 -05:00 by yindo · 1 comment
Owner

Originally created by @ZLeopard on GitHub (Jan 26, 2026).

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title.
  • I searched existing issues and didn't find this.
  • I can reproduce this with the latest released version.
  • I included a minimal reproducible example and steps to reproduce.

Area (Required)

  • deepagents (SDK)
  • cli

Reproduction Steps / Example Code (Python)

file path: libs/deepagents/deepagents/backends/sandbox.py
_WRITE_COMMAND_TEMPLATE = """python3 -c "
import os
import sys
import base64
import json

# Read JSON payload from stdin containing file_path and content (both base64-encoded)
payload_b64 = sys.stdin.read().strip()
if not payload_b64:
    print('Error: No payload received for write operation', file=sys.stderr)
    sys.exit(1)

try:
    payload = base64.b64decode(payload_b64).decode('utf-8')
    data = json.loads(payload)
    file_path = data['path']
    content = base64.b64decode(data['content']).decode('utf-8')
except Exception as e:
    print(f'Error: Failed to decode write payload: {e}', file=sys.stderr)
    sys.exit(1)

# Check if file already exists (atomic with write)
if os.path.exists(file_path):
    print(f'Error: File \\'{file_path}\\' already exists', file=sys.stderr)
    sys.exit(1)

# Create parent directory if needed
parent_dir = os.path.dirname(file_path) or '.'
os.makedirs(parent_dir, exist_ok=True)

with open(file_path, 'w') as f:
    f.write(content)
" <<'__DEEPAGENTS_EOF__'
{payload_b64}
__DEEPAGENTS_EOF__"""

cmd = _WRITE_COMMAND_TEMPLATE.format(payload_b64=payload_b64)

Error Message and Stack Trace (if applicable)

# Single atomic check + write command
>       cmd = _WRITE_COMMAND_TEMPLATE.format(payload_b64=payload_b64)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       KeyError: 'e'

Description

error code: except Exception as e:
print(f'Error: Failed to decode write payload: {e}', file=sys.stderr)
sys.exit(1)
fix: use {{e}} instead of {e}

Environment / System Info

No response

Originally created by @ZLeopard on GitHub (Jan 26, 2026). ### Checked other resources - [x] This is a bug, not a usage question. - [x] I added a clear and descriptive title. - [x] I searched existing issues and didn't find this. - [x] I can reproduce this with the latest released version. - [x] I included a minimal reproducible example and steps to reproduce. ### Area (Required) - [x] deepagents (SDK) - [x] cli ### Reproduction Steps / Example Code (Python) ```python file path: libs/deepagents/deepagents/backends/sandbox.py _WRITE_COMMAND_TEMPLATE = """python3 -c " import os import sys import base64 import json # Read JSON payload from stdin containing file_path and content (both base64-encoded) payload_b64 = sys.stdin.read().strip() if not payload_b64: print('Error: No payload received for write operation', file=sys.stderr) sys.exit(1) try: payload = base64.b64decode(payload_b64).decode('utf-8') data = json.loads(payload) file_path = data['path'] content = base64.b64decode(data['content']).decode('utf-8') except Exception as e: print(f'Error: Failed to decode write payload: {e}', file=sys.stderr) sys.exit(1) # Check if file already exists (atomic with write) if os.path.exists(file_path): print(f'Error: File \\'{file_path}\\' already exists', file=sys.stderr) sys.exit(1) # Create parent directory if needed parent_dir = os.path.dirname(file_path) or '.' os.makedirs(parent_dir, exist_ok=True) with open(file_path, 'w') as f: f.write(content) " <<'__DEEPAGENTS_EOF__' {payload_b64} __DEEPAGENTS_EOF__""" cmd = _WRITE_COMMAND_TEMPLATE.format(payload_b64=payload_b64) ``` ### Error Message and Stack Trace (if applicable) ```shell # Single atomic check + write command > cmd = _WRITE_COMMAND_TEMPLATE.format(payload_b64=payload_b64) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E KeyError: 'e' ``` ### Description error code: except Exception as e: print(f'Error: Failed to decode write payload: {e}', file=sys.stderr) sys.exit(1) fix: use {{e}} instead of {e} ### Environment / System Info _No response_
yindo added the bugdeepagentsexternal labels 2026-02-16 09:15:20 -05:00
yindo closed this issue 2026-02-16 09:15:20 -05:00
Author
Owner

@eyurtsev commented on GitHub (Feb 11, 2026):

A fix for this was merged ~1-2 weeks ago closing the issue

@eyurtsev commented on GitHub (Feb 11, 2026): A fix for this was merged ~1-2 weeks ago closing the issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagents#311