Skip to content

[Bug]: Sandbox system prompt and path normalizer hardcode "/workspace", ignoring the configured sandbox root #3645

Closed

Description

@Peng-io

Describe the bug

When the filesystem is sandbox-backed, the system prompt tells the model that the sandbox root is /workspace, and the filesystem tool's path normalizer strips exactly the /workspace prefix. Both values are hardcoded. They ignore the sandbox's actual workspace root, which comes from WorkspaceSpec.root and, for E2B, from E2bSandboxClientOptions.workspaceRoot (default /home/user).

As a result the model is told a directory that does not exist, and shell commands that use the advertised path fail.

To Reproduce

  1. Build a HarnessAgent with an E2B sandbox:

    new E2bFilesystemSpec()
            .apiKey(...)
            .templateId(...)
            .workspaceRoot("/home/user")
  2. Start a session and ask the model to run pwd and then echo hi > /workspace/x.txt.

  3. pwd returns /home/user (correct, matching the client option), but writing to /workspace fails with Permission denied — the directory does not exist and the sandbox user is not root.

The prompt itself is visibly wrong: it contains Sandbox root: /workspace (container id: ...).

Where it comes from

  • agentscope-harness/.../middleware/WorkspaceContextMiddleware.java:368 — hardcoded literal:

    sb.append("Sandbox root: /workspace (container id: ")
  • agentscope-harness/.../HarnessAgent.java:2708-2709 — the path normalizer is also pinned to the constant:

    pathNormalizer = WorkspacePathNormalizer.of(ShellPathPolicy.SANDBOX_WORKSPACE_PREFIX);
  • agentscope-harness/.../skill/runtime/ShellPathPolicy.java:46 — SANDBOX_WORKSPACE_PREFIX = "/workspace".

Meanwhile the filesystem layer reads the real root elsewhere:

  • agentscope-harness/.../filesystem/sandbox/SandboxBackedFilesystem.java:333-338 — resolveWorkspaceRoot() reads state.getWorkspaceSpec().getRoot().
  • agentscope-extensions-sandbox-e2b/.../E2bSandboxClientOptions.java:46 — workspaceRoot = "/home/user".

Why it is easy to hit

E2bFilesystemSpec exposes two independent setters with different defaults:

  • workspaceRoot(String) (line 73) → E2bSandboxClientOptions.workspaceRoot, default /home/user
  • workspaceSpec(WorkspaceSpec) (line 144) → WorkspaceSpec.root, default /workspace

Setting only the former (the natural choice, since it is the one that controls the E2B client) leaves the two roots disagreeing.

Expected behavior

The advertised sandbox root and the path normalizer prefix should be derived from the active workspace spec rather than hardcoded — e.g. the prompt can use sandbox.getState().getWorkspaceSpec().getRoot(), and HarnessAgent can build the normalizer from the configured spec (available at build time via the SandboxFilesystemSpec) instead of ShellPathPolicy.SANDBOX_WORKSPACE_PREFIX.

If deriving it is not feasible, exposing it as a configuration option would at least remove the hardcoded mismatch.

Environment

  • agentscope-java 2.0.4
  • E2B sandbox (Linux, non-root user), JDK 21

Activity

  1. logicwu0 commented on Oct 18, 2026

    @logicwu0
    Contributor

    I would like to work on this. I checked main at 40a4a57 and added local offline regression tests: an active sandbox with WorkspaceSpec.root=/home/user still advertises /workspace; the default E2B configuration and an explicit workspaceRoot("/custom/workspace") both leave WorkspaceSpec.root at /workspace. The three new assertions fail, while the two existing sandbox-prompt tests pass. No model or E2B service was contacted.

    Proposed scope:

    • Derive the advertised root and filesystem-tool path normalization from the sandbox bound to the current RuntimeContext, so resumed sessions and concurrent calls do not use a shared or build-time-only root.
    • Align the E2B effective WorkspaceSpec with its actual execution root, retaining /home/user as the E2B default and /workspace for the existing Docker default.
    • Keep paths outside the root subject to the existing filesystem/security policy; do not change sandbox lifecycle or snapshot behavior.
    • Cover default/custom roots, resume, per-call isolation, and existing Docker behavior with regression tests.

    One compatibility question before finalizing the E2B part: if callers explicitly set workspaceRoot(...) and workspaceSpec(...).root to different values, would you prefer rejecting that conflicting configuration, or preserving workspaceRoot(...) as authoritative and copying it into the effective WorkspaceSpec? I lean toward rejecting explicitly conflicting values instead of silently overriding one, but would like to confirm the intended contract. Existing persisted E2B state with differing roots also needs to retain the actual execution directory rather than be moved implicitly.

  2. chcodex commented on Oct 19, 2026

    @chcodex
    Contributor

    see #2194

  3. added a commit that references this issue on Nov 12, 2026
    6ff7590
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions