Skip to content

[Bug]: Sandbox mode system prompt is inconsistent with the container filesystem: host workspace path injected and sandbox root hard-coded to /workspace #3192

Open

Description

@devonking

AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.

Describe the bug
When a HarnessAgent runs with a Docker sandbox filesystem (DockerFilesystemSpec), the
system prompt injected by WorkspaceContextMiddleware contains two path statements that
are invalid or contradictory from the container's point of view:

  1. The workspace directory is: /app/workspace/office_master — this is the
    host-side harness workspace path (set via builder.workspace(...)). The path is
    never mounted into the container, so it does not exist inside the sandbox.
  2. Sandbox root: /workspace (container id: ...) — the container workspace root is
    hard-coded as /workspace in buildWorkspaceParagraph, ignoring the value actually
    configured via DockerFilesystemSpec.workspaceRoot(...) (stored in
    DockerSandboxState.workspaceRoot).

As a result, the model tries to access the advertised host path inside the container,
discovers it does not exist, and burns reasoning turns self-correcting (see thinking trace
below). On more complex tasks this can genuinely mislead the agent.

To Reproduce
Steps to reproduce the behavior:

  1. Your code
DockerFilesystemSpec filesystemSpec = getDefaultDockerFilesystemSpec();
filesystemSpec.image("python:3.12-slim");
filesystemSpec.memorySizeBytes(512* 1024 * 1024L);
filesystemSpec.cpuCount(1);
filesystemSpec.network("host");
// NOTE: workspaceRoot(...) is NOT set, so the container workspace root
// defaults to /workspace

HarnessAgent agent = HarnessAgent.builder()
        .name("office_master")
        .model(...)
        .workspace(Paths.get("/app/workspace/office_master")) // host-side harness workspace
        .filesystem(filesystemSpec)
        .build();
  1. How to execute
    run the agent with any prompt that makes it inspect its working directory / project files (e.g. "list the files in the workspace").
  2. See error
    the model's reasoning shows the confusion:
<thinking>
The workspace directory doesn't exist at that path. Let me check what directories are available.
The workspace directory is /workspace, not /app/workspace/office_master. Let me check the current working directory and project structure.
</thinking>

Expected behavior
Per the javadoc of buildWorkspaceParagraph, the workspace description should branch "by the active filesystem type so the LLM sees a description that matches its real deployment surface". In sandbox mode that means:

  • The session-context line The workspace directory is: %s should not present the host-side harness workspace path as a directory usable inside the container (it should be omitted or reworded for sandbox mode).
  • The Sandbox root: line should report the actual configured container workspace root (e.g. from DockerSandboxState.getWorkspaceRoot() / DockerSandboxClientOptions.getWorkspaceRoot()), not the hard-coded /workspace. With a custom workspaceRoot, the prompt is currently wrong in the opposite direction.

Error messages

No exception — this is a system-prompt / runtime-environment inconsistency. The observable symptom is the model's thinking trace above: the model discovers the advertised workspace directory does not exist, then falls back to /workspace on its own.

Environment (please complete the following information):

  • AgentScope-Java Version: 2.0.3
  • Java Version: 21
  • OS: Linux (Docker host, sandbox via Docker CLI)

Additional context

  • Root cause locations in agentscope-harness (verified on the v2.0.3 tag):
    • WorkspaceContextMiddleware.SESSION_CONTEXT_SECTION_TEMPLATE — The workspace directory is: %s is filled with workspaceManager.getWorkspace() (host path) regardless of filesystem type (agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/WorkspaceContextMiddleware.java, line 58).
    • WorkspaceContextMiddleware.buildWorkspaceParagraph — the sandbox branch appends the literal Sandbox root: /workspace instead of the configured root (agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/WorkspaceContextMiddleware.java, line 360).
  • The host-side workspace itself is by design: it holds AGENTS.md, MEMORY.md, sessions, skills and is the source of the workspace projection that is copied into the container at sandbox start. The bug is only that its host path is advertised to the model as a usable directory inside the container.
  • Workaround: setting filesystemSpec.workspaceRoot("/app/workspace/office_master") aligns the container root with the injected path, but the hard-coded Sandbox root: /workspace line still misleads whenever a custom root is configured, so a source fix is needed.
  • Suggested fix: in sandbox mode, derive the Sandbox root: line from the live sandbox state (the per-call sandbox bound by SandboxLifecycleMiddleware, or DockerSandboxState.workspaceRoot), and skip/reword the host workspace path in the session context section for sandbox filesystems.

Activity

  1. added
    bug
    on Sep 18, 2026
  2. oss-maintainer commented on Sep 18, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed

    Verified against current main (be7211d19):

    1. WorkspaceContextMiddleware.SESSION_CONTEXT_SECTION_TEMPLATE (line 58) renders The workspace directory is: %s from workspaceManager.getWorkspace() (line 217) — the host-side path — regardless of the active filesystem type. Inside a Docker sandbox that path does not exist, matching the confusion trace in the report.
    2. The sandbox branch of buildWorkspaceParagraph (line 368) appends the literal Sandbox root: /workspace (container id: ...), ignoring the actually configured root (DockerFilesystemSpec.workspaceRoot(...) → DockerSandboxState.getWorkspaceRoot()), so with a custom workspaceRoot the prompt is wrong in the opposite direction.

    Impact: agentscope-harness sandbox mode system prompt only; no data corruption, but it wastes model turns on self-correction and can mislead the agent when workspaceRoot is customized.
    Severity: medium.

    Next step: an automated fix proposal (spec) will be generated for this issue and posted here as a follow-up comment. The proposed direction matches yours — derive the Sandbox root: line from the live sandbox state, and omit/reword the host workspace path when a sandbox filesystem is active. Community members: please reply /approve to proceed with PR generation, or /revise / /reject to steer the proposal.


    Automated evaluation by github-manager-bot

  3. devonking commented on Sep 18, 2026

    @devonking
    Author
    • Third hard-coded location: HarnessAgent.Builder.build() creates the
      WorkspacePathNormalizer for FilesystemTool / ArtifactDeliveryTool with the literal
      ShellPathPolicy.SANDBOX_WORKSPACE_PREFIX (/workspace) instead of the configured
      DockerFilesystemSpec.workspaceRoot(...) (agentscope-harness/.../HarnessAgent.java,
      lines 2708-2710). With a custom workspace root, model-supplied paths starting with
      /workspace/ are silently re-rooted to the custom root, and absolute paths under the real
      root are passed through unnormalized.
    • The correct pattern already exists in the same method: the skill middleware's
      ShellPathPolicy reads defaultSandboxContext.getClientOptions().getWorkspaceRoot()
      (HarnessAgent.java lines 2903-2911). The pathNormalizer branch at 2708-2710 was likely
      missed in that fix.
  4. oss-maintainer commented on Sep 19, 2026

    @oss-maintainer
    Collaborator

    Follow-up evaluation — third hard-coded location confirmed, scope widened

    @devonking thanks — your addition checks out against main (d70910700, 2026-09-18). Verified point by point:

    Claim Result Evidence
    build() constructs the WorkspacePathNormalizer for FilesystemTool / ArtifactDeliveryTool with the literal /workspace confirmed HarnessAgent.java:2709-2711 → WorkspacePathNormalizer.of(ShellPathPolicy.SANDBOX_WORKSPACE_PREFIX); SANDBOX_WORKSPACE_PREFIX = "/workspace" at ShellPathPolicy.java:46
    The single-arg of(...) only strips that literal prefix (so a custom root is never stripped) confirmed WorkspacePathNormalizer.of(String) at :50-57 builds a one-entry prefix list with no configured root
    The skill-middleware branch already reads the configured root confirmed HarnessAgent.java:2904-2909 uses defaultSandboxContext.getClientOptions().getWorkspaceRoot(), falling back to the constant
    A custom root is actually configurable on the Docker path (so the mismatch is reachable, not theoretical) confirmed DockerFilesystemSpec.workspaceRoot(...) → DockerSandboxClientOptions.workspaceRoot(...); default /workspace at DockerSandboxClientOptions.java:39; consumed by DockerSandbox.java:148/205/264

    Both the pathNormalizer branch (:2709) and the skill branch (:2904) match the same AbstractSandboxFilesystem type (BaseSandboxFilesystem implements AbstractSandboxFilesystem, BaseSandboxFilesystem.java:55), so the divergence is purely an unwired call site, not a type-shape difference.

    Two more sites with the same defect that the thread has not listed yet

    • DockerSandboxClient.java:70-73 — re-hard-codes the default (: options.getWorkspaceRoot() != null ? … : "/workspace") instead of delegating to SandboxClientOptions.getWorkspaceRoot(). Harmless today because the options default is also /workspace, but it duplicates the default in a third place, which is how these drift.
    • SandboxClientOptions.java:61-63 — the base interface's getWorkspaceRoot() returns a literal /workspace rather than being abstract/delegating, so any backend that forgets to override silently reports Docker's root. Kubernetes is exposed through this: KubernetesSandboxClientOptions.java:32 and KubernetesSandboxState.java:29 carry their own workspaceRoot, and fix(sandbox): keep Kubernetes wrap newlines around command #3204 is fixing the Kubernetes wrap path separately.

    Revised scope of this issue — the report plus this thread now identify three value-level sites (not two), all needing the same treatment:

    1. SESSION_CONTEXT_SECTION_TEMPLATE renders the host workspace path in sandbox mode (WorkspaceContextMiddleware.java:58 + :217);
    2. buildWorkspaceParagraph prints a literal Sandbox root: /workspace (:368);
    3. new — pathNormalizer for FilesystemTool/ArtifactDeliveryTool uses the constant /workspace (HarnessAgent.java:2709-2711), which is the only one of the three that changes behaviour and not just prompt text: with a custom root, model-supplied /workspace/... paths get re-rooted to the real root, and absolute paths under the real root are passed through unnormalized.

    Items 1-2 are prompt-accuracy; item 3 is a path-resolution correctness issue, so it should be the anchor of the fix, with 1-2 following from the same resolved value.

    Updated fix direction (supersedes the direction in my initial evaluation): resolve the effective sandbox workspace root once — defaultSandboxContext.getClientOptions().getWorkspaceRoot() with the SANDBOX_WORKSPACE_PREFIX fallback already used at :2904-2909 — and feed that single value to (a) the pathNormalizer branch at :2709, (b) the Sandbox root: line in buildWorkspaceParagraph, and (c) the host-path line in SESSION_CONTEXT_SECTION_TEMPLATE (omit or reword it when a sandbox filesystem is active). Making SandboxClientOptions.getWorkspaceRoot() abstract is the structural cleanup that prevents recurrence; whether to do that here or in a follow-up is a maintainer call, since it touches every backend.

    Severity unchanged: medium — same blast radius (agentscope-harness only, no agentscope-core interface change), but item 3 makes the practical impact larger than "prompt wording" as originally assessed.

    Status of the proposal: no PR references #3192 as of this scan and no /approve has been received yet, so nothing has been generated. @zhangqian7741 (reporter) and @devonking: reply /approve and the spec will be regenerated against the three-site scope above (with a regression test that sets a custom workspaceRoot and asserts the normalizer strips the custom root, not /workspace), /revise <text> to steer it, or /reject to stop.


    Automated evaluation by github-manager-bot

  5. oss-maintainer commented on Sep 22, 2026

    @oss-maintainer
    Collaborator

    Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed

    The evaluation CTA above (5738509892, posted 2026-09-19T02:10:26Z) reached its 72-hour
    feedback limit at 2026-09-22T02:10:26Z with no own-line /approve, /revise, or /reject
    command in the thread, so per our workflow we skip PR generation and no competing PR will
    be filed from this proposal window. No action is needed from anyone.

    What the thread actually contains after that CTA: nothing. Measured at 02:12Z on
    2026-09-22, the window has zero non-bot comments after the CTA and zero reactions on it, so
    there was no signal to act on. @devonking and @zhangqian7741 — this is a timing stand-down,
    not a verdict on the report.

    The finding stands as evaluated, and the three value-level sites are still there on main:

    1. pathNormalizer for FilesystemTool / ArtifactDeliveryTool built from the constant
      /workspace (HarnessAgent.java:2709-2711 vs the configured-root branch at
      :2904-2909) — the behaviour-changing one: with a custom workspaceRoot, model-supplied
      /workspace/... paths get re-rooted and absolute paths under the real root pass through
      unnormalized.
    2. Sandbox root: /workspace printed literally in buildWorkspaceParagraph
      (WorkspaceContextMiddleware.java:368).
    3. The host workspace path rendered into SESSION_CONTEXT_SECTION_TEMPLATE in sandbox mode
      (WorkspaceContextMiddleware.java:58 + :217).

    Two duplication sites the thread surfaced are also unfixed:
    DockerSandboxClient.java:70-73 re-hard-codes the default instead of delegating to
    SandboxClientOptions.getWorkspaceRoot(), and SandboxClientOptions.java:61-63 returns a
    literal instead of being abstract.

    No PR references #3192 as of this check (searched across all states), so nothing else is
    carrying the fix — the gap is genuinely open, not covered elsewhere.

    @devonking if you still want the bot-generated PR, leave a one-line approve command on
    this issue and the spec will be regenerated against the three-site scope; a maintainer can
    also pick this up directly. Severity as assessed: medium, blast radius limited to
    agentscope-harness, no agentscope-core interface change.

    Automated by github-manager-bot

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions