agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]:2.0.5中创建subAgent因为filesystem是CompositeFilesystem,导致无法获取shell能力

Open BEN5890 opened this issue 1 week ago • 1 comments

if (sandboxFilesystemSpec != null) { capturedSandboxFs = new SandboxBackedFilesystem(); filesystem = filesystemRoutes.isEmpty() ? capturedSandboxFs : new RoutedSandboxFilesystem(capturedSandboxFs, filesystemRoutes);

            defaultSandboxContext = sandboxFilesystemSpec.toSandboxContext(resolvedWorkspace);

            if (isLocalSession(effectiveSession)) {
                log.warn(
                        "[harness] Sandbox mode is using a local AgentStateStore ({})."
                                + " Sandbox state will not survive JVM restarts and cannot be"
                                + " shared across instances. For production, configure a"
                                + " distributed AgentStateStore via .stateStore(...).",
                        effectiveSession.getClass().getSimpleName());
            }

            SessionSandboxStateStore stateStore =
                    new SessionSandboxStateStore(effectiveSession, resolvedAgentId);
            SandboxExecutionGuard executionGuard =
                    sandboxFilesystemSpec.getExecutionGuard() != null
                            ? sandboxFilesystemSpec.getExecutionGuard()
                            : SandboxExecutionGuard.noop();
            SandboxManager sandboxManager =
                    new SandboxManager(
                            defaultSandboxContext.getClient(),
                            stateStore,
                            resolvedAgentId,
                            executionGuard);
            sandboxLifecycleMw =
                    new SandboxLifecycleMiddleware(sandboxManager, capturedSandboxFs);
        } else if (!filesystemRoutes.isEmpty()) {
            filesystem = new CompositeFilesystem(filesystem, filesystemRoutes);
        }

因为subAgent的workspace:mode是shared,并且mainAgent设置了filesystemRoutes,导致进入了filesystem = new CompositeFilesystem(filesystem, filesystemRoutes);

io.agentscope.harness.agent.skill.runtime.ShellPathPolicy shellPolicy; boolean shellToolAvailable = !disableShellTool && ToolFilter.isAllowed(ShellExecuteTool.NAME, resolvedToolsConfig); if (!shellToolAvailable) { shellPolicy = io.agentscope.harness.agent.skill.runtime.ShellPathPolicy.noShell(); } else if (filesystem instanceof LocalFilesystemWithShell) { shellPolicy = io.agentscope.harness.agent.skill.runtime.ShellPathPolicy .localWithShell(resolvedWorkspace); } else if (filesystem instanceof OverlayFilesystem ov && ov.getUpper() instanceof LocalFilesystemWithShell) { shellPolicy = io.agentscope.harness.agent.skill.runtime.ShellPathPolicy .localWithShell(resolvedWorkspace); } else if (filesystem instanceof SandboxBackedFilesystem || (filesystem instanceof RoutedSandboxFilesystem routed && routed.primary() instanceof SandboxBackedFilesystem)) { String wsPrefix = defaultSandboxContext != null && defaultSandboxContext.getClientOptions() != null ? defaultSandboxContext.getClientOptions().getWorkspaceRoot() : io.agentscope.harness.agent.skill.runtime.ShellPathPolicy .SANDBOX_WORKSPACE_PREFIX; shellPolicy = io.agentscope.harness.agent.skill.runtime.ShellPathPolicy.sandbox( wsPrefix); } else { shellPolicy = io.agentscope.harness.agent.skill.runtime.ShellPathPolicy.noShell(); }在这里因为是CompositeFilesystem,无法注册execute工具,建议修改为 filesystem instanceof SandboxBackedFilesystem || (filesystem instanceof RoutedSandboxFilesystem routed && routed.primary() instanceof SandboxBackedFilesystem) || (filesystem instanceof CompositeFilesystem composite && composite.getDefaultBackend() instanceof SandboxBackedFilesystem) 这样修改就能是subAgent获得shell能力

BEN5890 avatar Nov 20 '26 08:11 BEN5890

I reproduced the mechanism while auditing the filesystem wrappers, and the scope is a bit wider than the subagent case: any filesystemRoute(...) makes the builder wrap the primary in a CompositeFilesystem, and that class is a routing layer — it implements neither execute/id nor the AbstractSandboxFilesystem marker. So:

  • shell_execute is never registered (the registration probe tests the marker on the wrapper), which is exactly the "no shell capability" you saw in the subagent;
  • the skill shell policy resolves to NO_SHELL, so every skill also loses its <files-root> and code-execution block;
  • the same happens in local mode when a route is declared over a LocalFilesystemWithShell.

Fix ready on fix/composite-shell-policy: a sandbox-backed primary is now wrapped in RoutedSandboxFilesystem (which is what filesystemRoute's own javadoc already promises), and the two capability probes resolve through the routing wrappers via a new FilesystemUtils.primaryBackend. Six new tests, including a builder-level regression that fails on main today. Opening the PR now.

ningmao-hlyz avatar Nov 20 '26 15:11 ningmao-hlyz