Skip to content

fix(#2397): replace inline python3 edit with download-edit-upload [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #2436

Open
waterWang wants to merge 1 commit into
agentscope-ai:mainfrom
waterWang:fix-sandbox-edit-no-python
Open

fix(#2397): replace inline python3 edit with download-edit-upload [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]#2436
waterWang wants to merge 1 commit into
agentscope-ai:mainfrom
waterWang:fix-sandbox-edit-no-python

Conversation

@waterWang

Copy link
Copy Markdown

Description

Fixes #2397

Restructures BaseSandboxFilesystem.edit() to use downloadFiles()FilesystemUtils.performStringReplacement()uploadFiles() instead of executing an inline Python script via python3 -c.

Problems Fixed

  1. \\n not recognized as newline by python3 -c — The old code used literal backslash+n to represent newlines in the Python script, but python3 -c treats \n as a line continuation character, causing SyntaxError.
  2. Manual JSON concatenation is fragilejsonEscape() only escaped \, ", \n, \r, \t, missing other JSON control characters (U+0000-U+0008, U+000B, U+000C, U+000E-U+001F). The new approach uses Java's String.replace() via FilesystemUtils.performStringReplacement().
  3. Hard dependency on python3 in sandbox imagesedit() was the only method requiring python3 in the sandbox image. All other methods (ls/grep/glob/write/read) use pure shell commands or the upload API. The fix removes this dependency.

Changes

  • BaseSandboxFilesystem.java: Rewrote edit() to download → edit → upload; removed jsonEscape() method; replaced import java.util.Base64 with import java.nio.charset.StandardCharsets

Testing

  • Existing tests pass (no regression)
  • Edit behavior is unchanged: same error messages for file not found / string not found / multiple occurrences
  • Sandbox images without python3 can now use edit()

Wallet: FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH

…it-upload [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@oss-maintainer

This comment was marked as abuse.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: fix(#2397): replace inline python3 edit with download-edit-upload

The approach is correct — replacing the fragile inline python3 -c script with a download → edit → upload pipeline eliminates:

  1. The \n vs newline interpretation issue
  2. Incomplete JSON escaping (jsonEscape() missing control chars)
  3. Hard dependency on python3 in sandbox images

However, CI is failing due to Spotless formatting violations in BaseSandboxFilesystem.java. Please run mvn spotless:apply and push the fix.

Code observations

  • Clean removal of jsonEscape() and Base64 import — good cleanup
  • Error handling for download/upload failures is thorough
  • Using FilesystemUtils.performStringReplacement() reuses existing tested logic

Once formatting is fixed, this should be good to merge.

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.

BaseSandboxFilesystem.edit() inline Python script has multiple bugs, should use download-edit-upload

2 participants