Skip to content

[Feature]: Host-own control-plane workspace files in sandbox mode; dedicated tools host-side, generic file/shell fail closed #3222

Open

Description

@chcodex

Is your feature request related to a problem? Please describe.

Follow-up to #2654 (sessions local-first vs MEMORY.md sandbox-only) and related symptom in #3110 (async memory flush fails with no active sandbox).

In sandbox mode (e.g. E2B), control-plane files are execution-plane writes:

  • WorkspaceManager.appendUtf8WorkspaceRelative / writeUtf8WorkspaceRelative go through filesystem.uploadFiles whenever a filesystem is present (WorkspaceManager.java:370-397,711-729), so MEMORY.md / memory/*.md (via MemorySaveTool:73-80, MemoryFlushManager:225-235) land inside the sandbox, never on host disk.
  • Reads are sandbox-first (readWithOverride:818-824, listMemoryFilePaths:939-974), so once a sandbox copy exists it shadows the host copy (split-brain).
  • The default projection whitelist (SandboxFilesystemSpec:42-43: AGENTS.md, skills, subagents, knowledge, .skills-cache) excludes these files, so a fresh sandbox from template loses them; durability depends on TAR/NATIVE snapshot instead.
  • tools.json is correctly host-side today (build-time ToolsConfigLoader.load via HarnessAgent:2726, MCP registered on host at HarnessAgent:2730), and execute in sandbox mode is E2B-bound (HarnessAgent:2690-2691) — the sandbox shell never sees host env. Memory/sessions should follow the same control-plane principle.

Describe the solution you'''d like

  1. Define a host-owned set: MEMORY.md, memory/, agents/ (sessions/tasks), plans/, tools.json (build-time read-only). Never add them to workspaceProjectionRoots; lock with a test on the projection payload.
  2. WorkspaceManager: add isHostOwned(path); host-owned reads/writes bypass the filesystem and go local (namespace-aware via resolveRuntimeDataPath; note the current local branch ignores namespace). Dedicated tools (memory_save/search/get, session_*/task_*, flush/consolidator, transcript writer) inherit host-side behavior with no per-tool changes. Generalize the existing precedent taskRecordsRouteToLiveSandbox:441-457.
  3. Fail closed on the generic surface in sandbox mode: read_file/write_file/edit_file/execute on host-owned paths return an error pointing to the dedicated tool (e.g. use memory_get/memory_save), instead of silent dual-write. Transparent per-prefix routing (RoutedSandboxFilesystem) is the heavier alternative and hides the boundary — not recommended.
  4. Tests: sandbox-mode memory_save lands on host disk + absent in sandbox glob; projection tar contains no host-owned paths; generic read_file MEMORY.md in sandbox returns the pointer error; memory survives sandbox recreate without snapshot.

Describe alternatives you'''ve considered

  • Status quo (memory lives in sandbox snapshot): couples memory durability to sandbox lifecycle, breaks cross-replica sharing and fresh-template starts.
  • Projection + write-back (add memory to projection roots, copy back on release): more code, write-conflict handling, still leaks via snapshots. Heavier than host-owning.

Additional context

Activity

  1. tanzzj commented on Sep 21, 2026

    @tanzzj
    Collaborator

    Both the memory stores designed in AS 2.0 and AS 1.0 depend on the filesystem. Once you remove the Memory.md in the sandbox, how does each pod get the latest memory file?

    But I do think that with a DistributedStore configured, storing agents/*/sessions|tasks in the sandbox is unnecessary.


    That said, this may relate to the other feature request: memory storage should support different storage types like Redis/JDBC, filesystem just a default option.

  2. oss-maintainer commented on Sep 21, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: enhancement | Status: Evaluated — valid, design questions to settle (verified against main @ 8ca0080)

    Claims verified against the current code. The core diagnosis holds:

    • Writes really do go sandbox-side whenever a filesystem is attached: appendUtf8WorkspaceRelative uploads through the filesystem (agentscope-harness/src/main/java/io/agentscope/harness/agent/workspace/WorkspaceManager.java:370-397, uploadFiles at :392-393), and writeUtf8WorkspaceRelative does the same (:711-729, :723-724). Only the filesystem == null branch stays local — there is no sandbox/host predicate at all.
    • MemorySaveTool (agent/tool/MemorySaveTool.java:48-80) and MemoryFlushManager (agent/memory/MemoryFlushManager.java:225-235, plus MemoryConsolidator.java:302 for curated MEMORY.md) write through exactly those helpers, so MEMORY.md / memory/*.md land in the sandbox.
    • Reads are filesystem-first with a host fallback (WorkspaceManager.java:818-824), so a sandbox copy shadows the host copy — the split-brain description is accurate.
    • Default projection roots are AGENTS.md, skills, subagents, knowledge, .skills-cache (agent/filesystem/spec/SandboxFilesystemSpec.java:41-42, applied at :127-141 and HarnessAgent.java:2459; tar built in agent/sandbox/WorkspaceProjectionApplier.java:50-134), which excludes memory paths — a fresh sandbox from template does start without them.
    • The cited precedent exists: taskRecordsRouteToLiveSandbox (WorkspaceManager.java:441-457, host-direct read :649-655, write :663-669). Line numbers in HarnessAgent have drifted — the build-time ToolsConfigLoader.load is at :2765, host-side MCP registration at :2769-2774, sandbox-bound execute at :2724-2725.
    • Durability does depend on snapshots: agentscope-extensions-sandbox-e2b/.../E2bSandbox.java:87-150 persists/restores the whole workspace via TAR (NATIVE_SNAPSHOT uses the platform snapshot API), and docs/v2/en/docs/harness/workspace.md:285 documents that as intended behaviour.

    Two corrections. (1) "tools.json is correctly host-side today" is only true in effect: agent/tools/ToolsConfigLoader.java:57-78 reads through the same sandbox-first two-layer path and swallows exceptions into Optional.empty() (:66-74), so an unreachable sandbox at build time silently yields no tools config rather than a host-side guarantee. (2) The proposed step 2 has a latent trap: resolveRuntimeDataPath is namespace-prefixed (WorkspaceManager.java:239-248) while the local read fallback is not (:823, and the local write helpers at :850-872, :882-913). Making host-owned paths namespace-aware on the write side without fixing the read fallback silently loses memory instead of exposing it.

    On the reviewer's question (@tanzzj — how does each pod get the latest memory file if MEMORY.md leaves the sandbox): the code already has a distributed answer, but it is mode-specific, not sandbox-mode-specific. Shared-store/remote mode routes MEMORY.md, tools.json, sessions/ and tasks/ into KV namespaces (docs/v2/en/docs/harness/filesystem.md:64-70), and cross-replica sandbox pickup needs a distributed AgentStateStore plus a non-Noop snapshot spec — configuring a DistributedStore does not change which filesystem mode is selected (DistributedStore.java:57-61). Today in sandbox mode the read fallback returns that pod's own host file, which is precisely the divergence being reported. Sessions are already asymmetric with memory: local-first with an async mirror into the filesystem (agent/memory/session/SessionTree.java:346, :583-598, :724-735), so host-owning memory would make the two paths consistent rather than invent a new pattern.

    Feasibility: feasible in the harness, but not as a single change. Fail-closed on generic tools is the risky half: the prompt already forbids write_file/edit_file on memory paths (agent/middleware/WorkspaceContextMiddleware.java:100-104), but reads and shell access are not restricted, and skills/scripts running inside the sandbox can currently read MEMORY.md because it is written there — closing that surface is an LLM-visible behaviour change that also contradicts published docs (workspace.md:285, skill.md:393), so it needs a doc/CHANGELOG decision, not just code.

    Test-coverage reality check: no existing test asserts memory placement in sandbox mode (the sandbox tests in agentscope-harness/src/test/java/io/agentscope/harness/agent/example/SandboxFilesystemIsolationScopeExampleTest.java:104-140 cover lifecycle/resume only), while MemoryConsolidatorFilesystemTest.java:94-115, HarnessAgentTest.java:1066-1090, RemoteFilesystemSpecTest.java:54-78 and ProjectAwareOverlayTest.java:106-118, :170-173, :325-347 would break if host-owning leaked out of sandbox mode. So host-owning must be gated strictly to SandboxBackedFilesystem, and existing sandbox-resident MEMORY.md needs a migration path or upgrading agents silently wake up with empty memory.

    Suggested minimal increment (for discussion): route-based host-owning of MEMORY.md and memory/ in sandbox mode via the existing filesystemRoute/RoutedSandboxFilesystem mechanism (agent/filesystem/RoutedSandboxFilesystem.java:41-74, agent/filesystem/CompositeFilesystem.java:76-137) + the namespace fix on the read fallback + projection and round-trip tests; defer the fail-closed behaviour change and agents//plans/ ownership to a follow-up.

    No bot-generated PR here: this spans harness core plus docs, needs a migration story, and the maintainers' call on the fail-closed boundary should be settled first.


    Automated evaluation by github-manager-bot

  3. added
    enhancement
    area/harness
    on Sep 21, 2026
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/harnessenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions