Repository navigation
feat(harness): add per-invocation skill credential hook - #4515
Open
shanuo0312 wants to merge 2 commits into
Open
shanuo0312 wants to merge 2 commits into
shanuo0312 wants to merge 2 commits into
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
shanuo0312
force-pushed
the
agent/fix-agentscope-4476-11531ff5ff08
branch
from
November 30, 2026 11:09
d238732 to
9e1714f
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved flaws can release skill credentials to unrelated scripts and expose secrets through exception messages and Docker process arguments.
5 open issues
Pass Docker credential values through the process environment · New Match skill paths on component boundaries · New Resolve relative skill paths from the execution directory · New Reject NUL-containing credentials without exposing values · New Recognize Windows separators in skill path attribution · New
What changed in this PR
Adds a per-invocation credential hook to Harness for shared skills, addressing #4476 while leaving authentication, authorization, and credential storage with the host.
Changes:
- Introduces the credential-provider API, command-to-skill attribution, and automatic provider inheritance by subagents.
- Adds per-command environment support across filesystem wrappers and sandbox backends.
- Adds focused tests and English/Chinese documentation covering usage and trust boundaries.
Tests and builds were not rerun during this review.
| File | Description |
|---|---|
| docs/v2/zh/docs/harness/skill.md | Documents credential configuration and limitations in Chinese. |
| docs/v2/en/docs/harness/skill.md | Documents credential configuration and limitations in English. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/tool/ShellExecuteToolSkillCredentialTest.java | Tests attribution, credential resolution, and rejection behavior. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/sandbox/SandboxEnvironmentTest.java | Tests fallback shell quoting and environment validation. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/sandbox/impl/docker/DockerSandboxRunCommandTest.java | Tests Docker environment arguments. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/local/LocalFilesystemWithShellTest.java | Tests per-command environment scoping. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/ShellExecuteTool.java | Resolves and validates credentials before execution. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/SkillRuntime.java | Exposes request-scoped catalog lookup. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/SkillInvocation.java | Carries skill, command, and caller context. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/SkillCredentialProvider.java | Defines the host credential-provider contract. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/SkillCredentialException.java | Represents credential-related execution rejection. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/SkillCatalog.java | Matches commands to visible skill roots. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/sandbox/SandboxEnvironment.java | Builds the one-shot POSIX environment wrapper. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/sandbox/Sandbox.java | Adds the per-invocation environment interface. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/sandbox/impl/docker/DockerSandbox.java | Adds native Docker environment injection. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/sandbox/AbstractBaseSandbox.java | Provides fallback environment-aware execution. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgentBuilderSupport.java | Propagates the provider to built-in subagent factories. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java | Adds builder configuration and shell-tool wiring. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/SandboxBackedFilesystem.java | Forwards environments to active sandboxes. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/AbstractSandboxFilesystem.java | Adds environment-aware execution with unsupported-backend rejection. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/RoutedSandboxFilesystem.java | Forwards environments to the primary backend. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/ProjectAwareOverlay.java | Forwards environments to the shell backend. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/OverlayFilesystem.java | Preserves environment forwarding through overlays. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/local/LocalFilesystemWithShell.java | Applies invocation variables to individual processes. |
| agentscope-extensions/agentscope-extensions-durable-sandbox/src/main/java/io/agentscope/extensions/durable/sandbox/LocalSandboxClient.java | Adds native environment injection for durable-local execution. |
Review effort: Balanced
| if (environment != null) { | ||
| for (Map.Entry<String, String> variable : environment.entrySet()) { | ||
| cmd.add("-e"); | ||
| cmd.add(variable.getKey() + "=" + variable.getValue()); |
| if (root == null || root.isEmpty()) { | ||
| continue; | ||
| } | ||
| if (root.length() > bestLength && command.contains(root)) { |
Comment on lines
+104
to
+105
| String relative = workspaceRelative(root); | ||
| if (relative != null && relative.length() > bestLength && command.contains(relative)) { |
| "the credential provider returned a null value for an environment" | ||
| + " variable"); | ||
| } | ||
| environment.put(name, variable.getValue()); |
| * when the root carries no recognizable workspace segment. | ||
| */ | ||
| private static String workspaceRelative(String root) { | ||
| int skills = root.lastIndexOf("/skills/"); |
shanuo0312
force-pushed
the
agent/fix-agentscope-4476-11531ff5ff08
branch
from
November 30, 2026 11:20
9e1714f to
8af6d46
Compare
…i#4476) Add SkillCredentialProvider so a host can resolve the authenticated caller's credentials for the selected skill immediately before a skill command runs, and inject them only into that command's environment. execute attributes a command to a visible skill when it references the skill's <files-root>; missing credentials reject the command with a tool error instead of running it. Native per-command environments are used where available (Docker, local shell, durable local sandbox); other sandbox backends get a one-shot POSIX env wrapper fallback. Docs (EN/ZH) describe the contract, missing-credential behavior and the trust boundary. Refs agentscope-ai#4476
shanuo0312
force-pushed
the
agent/fix-agentscope-4476-11531ff5ff08
branch
from
November 30, 2026 11:40
8af6d46 to
b27e636
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This is by an automated agent, not a human.
Summary
Adds a per-invocation credential hook for shared skills, addressing #4476.
A hosted, multi-tenant agent often runs one shared skill package for many users, while each user's external-service key must stay in host-owned encrypted storage and reach only the one skill command that needs it. The hook lets the host resolve credentials for the authenticated caller and the selected skill immediately before execution, and the harness applies them to that command only.
What changed
SkillCredentialProviderSPI (SkillInvocation,SkillCredentialException) underagentscope-harness, installed withHarnessAgent.Builder#skillCredentialProvider. Subagents inherit it.executeattributes a command to a visible skill when the command references that skill's<files-root>— absolute, workspace-relative, or via aworking_directoryinside the skill. The provider is called once, before execution, with the authenticatedRuntimeContextuser, the resolvedAgentSkill(frontmatter metadata included), the root and the command.AbstractSandboxFilesystem.execute(..., environment)andSandbox.exec(..., environment).docker exec -e, values taken from the docker client environment so they stay out of the container argv),LocalFilesystemWithShell, and the durable local sandbox (process environment).AbstractBaseSandboxbackends use a one-shot POSIXenvwrapper fallback; directSandboximplementations refuse a non-empty environment rather than silently dropping credentials.The framework stores, logs and persists nothing. Values are never written to the skill directory, workspace, marketplace cache, snapshot, prompt, tool arguments/results or agent state.
Verification
mvn -T1C -pl agentscope-harness -am test(full harness test suite, including newShellExecuteToolSkillCredentialTest,SandboxEnvironmentTest,LocalFilesystemWithShellTestandDockerSandboxRunCommandTestcases).mvn -T1C -DskipTests compileover the full reactor.mvn -pl agentscope-harness spotless:apply(check clean).Limitations
envprefix, so values can appear in that backend's command text/logs. Prefer a native backend for high-value secrets, or overrideSandbox.exec(..., environment).