Skip to content

fix(sandbox): use base64+stdin for edit() to avoid bash -lc escaping … - #3084

Open
gh-zhaoweifeng wants to merge 2 commits into
agentscope-ai:mainfrom
gh-zhaoweifeng:fix/edit-file-e2b-sandbox
Open

fix(sandbox): use base64+stdin for edit() to avoid bash -lc escaping …#3084
gh-zhaoweifeng wants to merge 2 commits into
agentscope-ai:mainfrom
gh-zhaoweifeng:fix/edit-file-e2b-sandbox

Conversation

@gh-zhaoweifeng

Copy link
Copy Markdown

…issues

In E2B sandbox environments, the shell is bash -lc, which treats \n inside double quotes as a literal backslash+n (not a newline). This causes the entire multi-line Python script in python3 -c "...\n..." to collapse into a single line, failing with:

SyntaxError: unexpected character after line continuation character

This makes the edit_file tool 100% non-functional in sandbox environments. The model falls back to write_file, which refuses to overwrite existing files, so no file can be modified at all.

This fix base64-encodes the Python script (assembled with real newlines) and pipes it through stdin to python3 -, passing the payload via argv[1]. This avoids all quoting/escaping issues and works correctly in both sandbox and non-sandbox environments.

The command shape changes from:

python3 -c "...\n..." 2>&1 <<'EDIT_EOF'

EDIT_EOF

to:

echo | base64 -d | python3 - 2>&1

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.12, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

…issues

In E2B sandbox environments, the shell is `bash -lc`, which treats `\n`
inside double quotes as a literal backslash+n (not a newline). This causes
the entire multi-line Python script in `python3 -c "...\n..."` to collapse
into a single line, failing with:

  SyntaxError: unexpected character after line continuation character

This makes the `edit_file` tool 100% non-functional in sandbox environments.
The model falls back to `write_file`, which refuses to overwrite existing
files, so no file can be modified at all.

This fix base64-encodes the Python script (assembled with real newlines)
and pipes it through stdin to `python3 -`, passing the payload via argv[1].
This avoids all quoting/escaping issues and works correctly in both
sandbox and non-sandbox environments.

The command shape changes from:

  python3 -c "...\n..." 2>&1 <<'__EDIT_EOF__'
  <payload>
  __EDIT_EOF__

to:

  echo <scriptB64> | base64 -d | python3 - <payloadB64> 2>&1
@CLAassistant

CLAassistant commented Sep 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Add test to verify that edit() uses 'base64 -d | python3 -' instead of
'python3 -c' inline form, which fails in bash -lc environments.

This improves patch coverage for the fix in commit b00209d.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants