Skip to content

[Bug]:Shell execution can escape LocalFilesystemWithShell RuntimeContext namespace #1777

Closed

Description

@lizhifuabc

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:

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

Activity

  1. added
    bug
    on Jun 16, 2026
  2. guslegend0510 commented on Jun 16, 2026

    @guslegend0510
    Contributor

    我提交了一个PR,麻烦审核一下

  3. added
    area/harness
    on Jun 17, 2026
  4. moved this from Backlog to In progress in AgentScope Javaon Jun 18, 2026
  5. moved this from In progress to Done in AgentScope Javaon Jun 26, 2026
  6. added a commit that references this issue on Jun 26, 2026
    dbc82fe
  7. added a commit that references this issue on Aug 12, 2026
    06dbe65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/harnessbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions