Skip to content

fix: apply isolation namespace to shell execute cwd (#2329) [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #2435

Open
waterWang wants to merge 1 commit into
agentscope-ai:mainfrom
waterWang:fix-2329-isolation-scope-execute-cwd
Open

fix: apply isolation namespace to shell execute cwd (#2329) [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]#2435
waterWang wants to merge 1 commit into
agentscope-ai:mainfrom
waterWang:fix-2329-isolation-scope-execute-cwd

Conversation

@waterWang

Copy link
Copy Markdown

Description

When IsolationScope.SESSION or IsolationScope.USER is configured, the LocalFilesystemWithShell correctly creates a namespace-aware working directory (e.g., <workspace>/<sessionId>/). However, the resolveExecuteCwd() method short-circuits when shellCwd is set (the project root), returning shellCwd directly without applying the namespace prefix. This causes shell commands to run in the project root instead of the isolated session directory, leading to failures when the agent tries to execute scripts that were generated in the isolated workspace.

Root Cause

In LocalFilesystemWithShell.resolveExecuteCwd():

if (shellCwd != null) {
    return shellCwd;  // ← BUG: skips namespace resolution entirely
}

When shellCwd is set (to the project root), the method returns immediately without checking the NamespaceFactory, so the shell always runs in the project root regardless of the configured isolation scope.

Fix

Use shellCwd (or getCwd() as fallback) as the base path, then apply namespace resolution on top of it:

Path base = shellCwd != null ? shellCwd : getCwd();
// ... then apply namespace on top of base

This ensures that when isolation scope is configured, the shell's working directory becomes <projectRoot>/<sessionId>/ (or <workspace>/<sessionId>/) instead of <projectRoot>/.

Testing

  • The existing LocalFilesystemUserIsolationExampleTest and SandboxFilesystemIsolationScopeExampleTest should pass with this fix
  • Commands executed via execute_shell_command will now correctly resolve to the isolated namespace directory

Fixes #2329

…) [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.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ent/filesystem/local/LocalFilesystemWithShell.java 25.00% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@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.

Summary

Fix correctly applies namespace isolation on top of shellCwd instead of bypassing it when shellCwd is set.

Analysis

Previously, resolveExecuteCwd() returned shellCwd directly when it was non-null, skipping namespace resolution entirely. This meant that under IsolationScope.SESSION or IsolationScope.USER, shell commands executed with an explicit shellCwd would escape the isolation namespace — a correctness bug.

The fix extracts a base path (preferring shellCwd over getCwd()) and then applies namespace segments on top, ensuring isolation is always enforced.

Verdict

Clean, minimal fix. Logic is correct. Build passes.

Note: #2434 appears to be a duplicate of this PR for the same issue (#2329). Consider closing one.

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.

[Bug]:IsolationScope (SESSION/USER) does not apply to execute_shell_command working_directory

2 participants