Skip to content

fix(harness): replace inline Python edit with download-edit-upload in BaseSandboxFilesystem#2398

Open
chcodex wants to merge 1 commit into
agentscope-ai:mainfrom
chcodex:fix/sandbox-edit-python-to-java
Open

fix(harness): replace inline Python edit with download-edit-upload in BaseSandboxFilesystem#2398
chcodex wants to merge 1 commit into
agentscope-ai:mainfrom
chcodex:fix/sandbox-edit-python-to-java

Conversation

@chcodex

@chcodex chcodex commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace the fragile inline Python script in BaseSandboxFilesystem.edit() with a download → Java replacement → upload approach, using the same FilesystemUtils.performStringReplacement() shared by LocalFilesystem and RemoteFilesystem.

Bugs Fixed

  1. \n not recognized by python3 -c — Java's \\n was passed literally, causing SyntaxError
  2. jsonEscape() incomplete — missing JSON control characters caused json.loads() failures
  3. Hard python3 dependency — now removed

Changes

File Change
BaseSandboxFilesystem.java Rewrite edit(), remove jsonEscape(), StandardCharsets import
FilesystemUtils.java Add ReplacementResult record, change return type from Object[]
LocalFilesystem.java Adapt to ReplacementResult
RemoteFilesystem.java Adapt to ReplacementResult
BaseSandboxFilesystemTest.java Add EditSpyFilesystem stub + 8 unit tests + 7 integration tests, real downloadFiles/uploadFiles

Tests

47 tests passing across 4 test classes, 0 failures:

  • BaseSandboxFilesystemTest: 22 tests (13 unit + 9 integration)
  • FilesystemToolTest: 5 tests
  • LocalFilesystemModeTest: 16 tests
  • CompositeFilesystemTest: 4 tests

Fixes #2397

… BaseSandboxFilesystem

Bug: BaseSandboxFilesystem.edit() used an inline Python script via
python3 -c with heredoc to perform string replacement. This approach
had three issues:
1. \n in Java string is not a newline separator for python3 -c
2. jsonEscape() missed JSON control characters, causing parse errors
3. Hard dependency on python3 in sandbox images

Fix: Restructure edit() to download file content via downloadFiles(),
perform replacement using FilesystemUtils.performStringReplacement()
(shared with LocalFilesystem and RemoteFilesystem), then upload the
result via uploadFiles().

Also:
- Add FilesystemUtils.ReplacementResult record for type-safe returns
- Fix empty file guard semantics (null || length == 0)
- Remove jsonEscape() and unused Base64 import
- Use StandardCharsets.UTF_8 import instead of fully qualified name

Tests: 47 tests passing across BaseSandboxFilesystemTest (22),
FilesystemToolTest (5), LocalFilesystemModeTest (16),
CompositeFilesystemTest (4). Covers unit (stubbed download/upload)
and integration (real file I/O) scenarios including special
characters, replaceAll, and error paths.
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

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

1 participant