Skip to content

feat(harness): add per-invocation skill credential hook - #4515

Open
shanuo0312 wants to merge 2 commits into
agentscope-ai:mainfrom
shanuo0312:agent/fix-agentscope-4476-11531ff5ff08
Open

shanuo0312 wants to merge 2 commits into
agentscope-ai:mainfrom
shanuo0312:agent/fix-agentscope-4476-11531ff5ff08

Conversation

@shanuo0312

@shanuo0312 shanuo0312 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

  • New SkillCredentialProvider SPI (SkillInvocation, SkillCredentialException) under agentscope-harness, installed with HarnessAgent.Builder#skillCredentialProvider. Subagents inherit it.
  • execute attributes a command to a visible skill when the command references that skill's <files-root> — absolute, workspace-relative, or via a working_directory inside the skill. The provider is called once, before execution, with the authenticated RuntimeContext user, the resolved AgentSkill (frontmatter metadata included), the root and the command.
  • Missing credentials (provider throws) or malformed provider output rejects the command with a tool error instead of running it; commands are never replayed.
  • Per-invocation environment channel: AbstractSandboxFilesystem.execute(..., environment) and Sandbox.exec(..., environment).
    • Native where supported: Docker (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).
    • Other AbstractBaseSandbox backends use a one-shot POSIX env wrapper fallback; direct Sandbox implementations refuse a non-empty environment rather than silently dropping credentials.
  • Docs (EN + ZH): new "Per-user credentials for shared skills" section covering the contract, missing-credential behavior, injection guarantees and the trust boundary.

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 new ShellExecuteToolSkillCredentialTest, SandboxEnvironmentTest, LocalFilesystemWithShellTest and DockerSandboxRunCommandTest cases).
  • mvn -T1C -DskipTests compile over the full reactor.
  • mvn -pl agentscope-harness spotless:apply (check clean).

Limitations

  • Attribution is path-based: instruction-only skills whose commands never reference the skill root do not trigger the hook.
  • Sandbox backends without native per-command environment support receive the fallback env prefix, so values can appear in that backend's command text/logs. Prefer a native backend for high-value secrets, or override Sandbox.exec(..., environment).
  • Docker behavior is verified at the generated-argv level (no live container is required); the other sandbox extensions inherit the documented fallback and were not exercised against live services.

Copilot AI balanced review requested due to automatic review settings November 30, 2026 11:06
@mintlify

mintlify Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 8aa81d1.

Approve preview

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved flaws can release skill credentials to unrelated scripts and expose secrets through exception messages and Docker process arguments.

5 open issues
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
shanuo0312 force-pushed the agent/fix-agentscope-4476-11531ff5ff08 branch from 9e1714f to 8af6d46 Compare November 30, 2026 11:20
…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

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.

3 participants