fix(sandbox): use base64+stdin for edit() to avoid bash -lc escaping … - #3084
Open
gh-zhaoweifeng wants to merge 2 commits into
Open
fix(sandbox): use base64+stdin for edit() to avoid bash -lc escaping …#3084gh-zhaoweifeng wants to merge 2 commits into
gh-zhaoweifeng wants to merge 2 commits into
Conversation
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…issues
In E2B sandbox environments, the shell is
bash -lc, which treats\ninside double quotes as a literal backslash+n (not a newline). This causes the entire multi-line Python script inpython3 -c "...\n..."to collapse into a single line, failing with:SyntaxError: unexpected character after line continuation character
This makes the
edit_filetool 100% non-functional in sandbox environments. The model falls back towrite_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.
mvn spotless:applymvn test)