Repository navigation
Closed
Labels
Description
Describe the bug
When using HarnessAgent with LocalFilesystemWithShell and a NamespaceFactory for
per-user/per-session workspace isolation, shell commands executed through the default
ShellExecuteTool do not reliably stay inside the RuntimeContext namespace directory.
This causes skills that write files to the current working directory to generate files
under the shared workspace root instead of the current user's session workspace.
There are two related issues in the current implementation:
AguiAgentAdapter.run(...)calls:
agent.stream(msgs, options)
There is no RuntimeContext parameter in this path. If the wrapped agent is a HarnessAgent,
this can eventually use RuntimeContext.empty(), causing LocalFilesystemWithShell to fall
back to the workspace root.
2. ShellExecuteTool.execute(...) prepends working_directory directly:
if (workingDirectory != null && !workingDirectory.isBlank()) {
effectiveCommand = "cd " + workingDirectory + " && " + command;
}
working_directory is not validated, normalized, quoted, or restricted to the
RuntimeContext namespace. If the model passes an absolute path, .., or the workspace root,
it can override the namespaced cwd resolved by LocalFilesystemWithShell.
To Reproduce
1. Configure a HarnessAgent with LocalFilesystemWithShell.
2. Set shellCwd to null.
3. Configure a NamespaceFactory that returns a per-user/per-session namespace, for
example:
users/default/{userId}/sessions/{sessionId}
4. Invoke the agent through AG-UI or execute the default shell tool.
5. Ask the agent to run:
pwd
6. Or execute a skill that writes files to the current working directory.
Expected behavior
Shell commands should execute inside the RuntimeContext namespace directory, for example:
workspace/users/default/{userId}/sessions/{sessionId}
working_directory should also be resolved relative to that namespace and should not be
able to escape it.
Actual behavior
Shell execution may run in the shared workspace root:
workspace/
As a result, generated skill files are written to a global shared directory instead of the
current user's session workspace.
Error messages
There is no exception. The behavior is observable from pwd output and generated file
locations.
Environment
- AgentScope-Java Version: 2.0.0-RC3
- Java Version: 21
- OS: macOS
Additional context
Relevant code:
ShellExecuteTool.execute(...):
if (workingDirectory != null && !workingDirectory.isBlank()) {
effectiveCommand = "cd " + workingDirectory + " && " + command;
}
LocalFilesystemWithShell.resolveExecuteCwd(...) falls back to getCwd() when namespace is
empty:
List<String> ns = nsf.getNamespace(rc);
if (ns == null || ns.isEmpty()) {
return getCwd();
}
A safer behavior would be:
- AG-UI adapter should provide a way to pass RuntimeContext.
- ShellExecuteTool should validate and normalize working_directory.
- working_directory should be resolved relative to the effective namespaced cwd, not the
global workspace root.
- Absolute paths and parent-directory escapes should be rejected.Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
guslegend0510 commentedon Jun 16, 2026
我提交了一个PR,麻烦审核一下
fix(shell): validate working_directory to prevent namespace escape (a…
fix(shell): validate working_directory to prevent namespace escape (a…