Skip to content

fix(harness): isolate subagent sandbox contexts and reject GLOBAL sandbox subagents (port to 2.0.x) - #4581

Open
Ernest-L wants to merge 2 commits into
agentscope-ai:2.0.xfrom
Ernest-L:port/sandbox-context-isolation-2.0.x
Open

Ernest-L wants to merge 2 commits into
agentscope-ai:2.0.xfrom
Ernest-L:port/sandbox-context-isolation-2.0.x

Conversation

@Ernest-L

@Ernest-L Ernest-L commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@juruO-o — heads-up that jujn's 3181063 (merged to main via #4441) had not reached
2.0.x: #4520 was cut before that commit existed on the PR branch. This PR ports it,
while keeping the rollout guidance you asked for in the 2.0.x docs (the GLOBAL
sentences are updated to the new build-time rejection behavior instead of the original
commit's deleted "blocks on the lease" wording).

What this ports

3181063 (jujn, merged to main via #4441) for code and tests:

  1. DefaultAgentManager — extracts childContext(sessionId, userId, parent) and strips
    the framework-default AbstractFilesystem and SandboxContext inherited from the
    parent runtime context (caller-managed externalSandbox / externalSandboxState
    sharing is preserved), so an ISOLATED declared subagent installs its own sandbox
    context and workspace projection instead of silently reusing the parent's. Adapted to
    2.0.x, where the context construction is inlined in invokeAgent /
    invokeAgentStream and lacks the main-era typed-attribute strips;
  2. HarnessAgent.build — fails fast with IllegalStateException when GLOBAL sandbox
    isolation is combined with subagents (a nested child would block on the lease its
    parent holds for the whole call);
  3. New tests: DefaultAgentManagerSandboxContextTest, HarnessAgentGlobalSandboxSubagentTest.

Doc handling (differs from the original commit)

The original commit deleted the four doc paragraphs added by #4441 — two GLOBAL
sentences in them were stale after this change ("blocks on the lease"), while the rest
was still valid. On 2.0.x this PR keeps the paragraphs and instead rewrites the
GLOBAL sentences to "rejected at build time", and adds the new isolation behavior to
the subagent.md "Sandbox mode" note — keeping mainline and 2.0.x in lockstep. A
companion PR to main restores the same guidance there (cross-referenced).

Tests

  • Full-reactor mvn clean verify on this branch with the CI Windows flags
    (-Djacoco.skip=true -DskipDurableWindowsTests=true): 114 modules,
    11,890 tests, 0 failures, 0 errors, including the two ported test classes;
  • HarnessAgentTest#workspaceForKeepsSandboxHostRoutingAndConfiguredNamespace was
    adapted: its @EnumSource enumerates all IsolationScope values, and the GLOBAL
    parameter now asserts the build-time IllegalStateException (this test no longer
    exists on mainline, which is why upstream CI did not hit the rejection).

Compatibility

Related

…dbox subagents (port to 2.0.x)

Port jujn's 3181063 (merged to main via agentscope-ai#4441) to the 2.0.x line:

- DefaultAgentManager: extract childContext(sessionId, userId, parent) and strip
  the framework-default AbstractFilesystem and SandboxContext inherited from the
  parent runtime context (caller-managed externalSandbox / externalSandboxState
  sharing is preserved), so an ISOLATED declared subagent installs its own sandbox
  context and workspace projection instead of silently reusing the parent's;
  adapted to 2.0.x where the context construction is inlined in invokeAgent /
  invokeAgentStream and lacks the main-era typed-attribute strips
- HarnessAgent.build: fail fast with IllegalStateException when GLOBAL sandbox
  isolation is combined with subagents (a nested child would block on the lease
  its parent holds for the whole call)
- new tests: DefaultAgentManagerSandboxContextTest, HarnessAgentGlobalSandboxSubagentTest;
  adapted to 2.0.x (no journalEnabled builder, MiddlewareBase is an interface without
  activePoints, projection entry uses the literal __workspace_projection__ key)
- docs: GLOBAL sentences rewritten from 'blocks on the lease' to 'rejected at build
  time'; subagent.md notes the new isolation behavior

Unlike the original commit, the doc paragraphs are kept (not deleted) and updated to
match the new behavior, keeping 2.0.x and mainline in lockstep per juruoO-o's review.
The parameterized workspaceForKeepsSandboxHostRoutingAndConfiguredNamespace
test enumerates all IsolationScope values; with the new build-time rejection
the GLOBAL parameter now asserts the IllegalStateException instead of
building an agent (mainline removed this test before the rejection landed,
which is why upstream CI did not hit it).
@Ernest-L

Ernest-L commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Companion mainline PR for the doc restore + coverage test lost in the #4441 squash: #4582 (@jujn for review/merge). It restores the rollout guidance juruoO-o asked for, rewrites the stale GLOBAL sentences to the new build-time rejection, and re-adds the null-agentId branch test. Cross-referenced with #4581 so mainline and 2.0.x stay in lockstep.

@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...pe/harness/agent/subagent/DefaultAgentManager.java 80.00% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@Ernest-L

Ernest-L commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@juruO-o friendly ping for review when convenient — this ports jujn's 3181063 to 2.0.x (see description for what and why, including how the doc handling differs from the original commit).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant