Skip to content

Fix sandbox skill <location> paths - #7915

Closed
sunnoy wants to merge 3 commits into
openclaw:mainfrom
sunnoy:fix/sandbox-skill-location
Closed

sunnoy wants to merge 3 commits into
openclaw:mainfrom
sunnoy:fix/sandbox-skill-location

Conversation

@sunnoy

@sunnoy sunnoy commented Feb 3, 2026 •

Copy link
Copy Markdown

Fixes #6346.

When sandbox is enabled, build the skills prompt from sandbox workspace entries (not cached snapshot) so skill paths stay under the host-side sandbox root and Read no longer fails with 'Path escapes sandbox root'.

Commit: 05ca190

Greptile Overview

Greptile Summary

This PR changes how the embedded runner builds the skills prompt and applies skill env overrides when sandboxing is enabled. Instead of preferring a cached skills snapshot, it forces a fresh load of workspace skill entries and prefers entries over snapshot prompts so that generated skill <location> paths remain under the host-side sandbox workspace root (avoiding Read failures like “Path escapes sandbox root”).

The behavior change is implemented in both the run attempt path and the compaction path, and resolveSkillsPromptForRun is updated to prefer entries over a snapshot prompt with a corresponding unit test update.

Confidence Score: 3/5

  • This PR is likely safe to merge, but there are a couple of correctness risks around skill loading under sandboxing and a test/type issue that should be addressed first.
  • The core change (prefer building the skills prompt from entries) is straightforward and has a targeted test update, but the updated sandbox path logic may load skills from the sandbox root rather than the actual workspace in some configurations, and the new test currently references an unimported type (SkillEntry) which can fail compilation.
  • src/agents/pi-embedded-runner/run/attempt.ts, src/agents/pi-embedded-runner/compact.ts, src/agents/skills.resolveskillspromptforrun.test.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

When sandbox is enabled, build skills prompt from sandbox workspace entries (not cached snapshot) so Read uses paths under the sandbox root. Updates prompt resolution order and adjusts tests.\n\nRefs: openclaw#6346
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Feb 3, 2026

@greptile-apps greptile-apps Bot 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.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +29 to +32
it("prefers entries when provided (even if snapshot exists)", () => {
const entry: SkillEntry = {
skill: {
name: "demo-skill",

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.

[P1] This test uses SkillEntry without importing the type, so it will fail TypeScript compilation under typical TS/Vitest settings.

Suggested change
it("prefers entries when provided (even if snapshot exists)", () => {
const entry: SkillEntry = {
skill: {
name: "demo-skill",
import type { SkillEntry } from "./skills/types.js";
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/skills.resolveskillspromptforrun.test.ts
Line: 29:32

Comment:
[P1] This test uses `SkillEntry` without importing the type, so it will fail TypeScript compilation under typical TS/Vitest settings.

```suggestion
import type { SkillEntry } from "./skills/types.js";
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +167 to 189
const shouldLoadSkillEntries =
sandbox?.enabled === true || !params.skillsSnapshot || !params.skillsSnapshot.resolvedSkills;
const skillEntries = shouldLoadSkillEntries
? loadWorkspaceSkillEntries(effectiveWorkspace)
: [];
restoreSkillEnv = params.skillsSnapshot
? applySkillEnvOverridesFromSnapshot({
snapshot: params.skillsSnapshot,
restoreSkillEnv = shouldLoadSkillEntries
? applySkillEnvOverrides({
skills: skillEntries ?? [],
config: params.config,
})
: applySkillEnvOverrides({
skills: skillEntries ?? [],
: applySkillEnvOverridesFromSnapshot({
snapshot: params.skillsSnapshot,
config: params.config,
});

const skillsPrompt = resolveSkillsPromptForRun({
skillsSnapshot: params.skillsSnapshot,
skillsSnapshot: sandbox?.enabled ? undefined : params.skillsSnapshot,
entries: shouldLoadSkillEntries ? skillEntries : undefined,
config: params.config,
// Note: tools enforce sandbox paths against the host-side sandbox workspace root,
// so skill <location> should stay within that host path (not the container mount path).
workspaceDir: effectiveWorkspace,
});

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.

[P1] When sandbox.enabled is true, effectiveWorkspace can be sandbox.workspaceDir (the host-side sandbox root), but this change loads skills from loadWorkspaceSkillEntries(effectiveWorkspace). If sandbox.workspaceDir is not the project workspace, this will look in the sandbox root’s skills/ directory rather than the user’s intended workspace, and may silently drop workspace skills.

If the intent is “build prompt from entries using host-side paths” but still resolve skills from the original workspace, consider loading entries from resolvedWorkspace (or whichever path actually contains the workspace skills) and only using effectiveWorkspace when building <location> paths.

Also appears in src/agents/pi-embedded-runner/compact.ts around the same logic.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.ts
Line: 167:189

Comment:
[P1] When `sandbox.enabled` is true, `effectiveWorkspace` can be `sandbox.workspaceDir` (the host-side sandbox root), but this change loads skills from `loadWorkspaceSkillEntries(effectiveWorkspace)`. If `sandbox.workspaceDir` is *not* the project workspace, this will look in the sandbox root’s `skills/` directory rather than the user’s intended workspace, and may silently drop workspace skills.

If the intent is “build prompt from entries using host-side paths” but still resolve skills from the *original* workspace, consider loading entries from `resolvedWorkspace` (or whichever path actually contains the workspace skills) and only using `effectiveWorkspace` when building `<location>` paths.

Also appears in `src/agents/pi-embedded-runner/compact.ts` around the same logic.

How can I resolve this? If you propose a fix, please make it concise.

@sunnoy

sunnoy commented Feb 3, 2026

Copy link
Copy Markdown
Author

Thanks for the review!

  • Re: SkillEntry type in src/agents/skills.resolveskillspromptforrun.test.ts: fixed by adding an explicit import type { SkillEntry } from "./skills.js" (re-exported from ./skills/types.js).

  • Re: loading entries from effectiveWorkspace under sandbox:
    In non-RW sandbox mode, resolveSandboxContext() syncs skills into sandbox.workspaceDir via syncSkillsToWorkspace({ sourceWorkspaceDir: agentWorkspaceDir, targetWorkspaceDir: sandboxWorkspaceDir, ... }).
    We intentionally load skill entries from effectiveWorkspace so the generated <location> paths point to the host-side sandbox workspace root (required by tool path enforcement) and Read no longer fails with “Path escapes sandbox root” ([Bug]: Sandbox skill <location> in system prompt uses host path instead of sandbox path #6346).

@sunnoy sunnoy left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Greptile review follow-up:

1. SkillEntry import (P1) - Already fixed in commit 6f91855.

2. Sandbox effectiveWorkspace loading skills from wrong dir (P1) - This is a false positive. When sandbox.enabled is true and workspaceAccess !== "rw", resolveSandboxContext() explicitly calls syncSkillsToWorkspace() (see src/agents/sandbox/context.ts lines 53-59) to copy skills from the agent workspace to sandbox.workspaceDir before returning. So loadWorkspaceSkillEntries(effectiveWorkspace) correctly finds the synced skills. The comments in both attempt.ts and compact.ts already document why effectiveWorkspace is used for <location> paths (tool path enforcement against the host-side sandbox root).

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Feb 21, 2026
@sunnoy sunnoy closed this Feb 22, 2026
@sunnoy sunnoy reopened this Feb 26, 2026
@greptile-apps

greptile-apps Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes issue #6346 by ensuring skill <location> paths stay within the sandbox root when sandbox mode is enabled. The fix works by:

  • When sandbox.enabled is true, forcing fresh skill loading from the sandbox workspace directory instead of using cached snapshots
  • Reordering the priority in resolveSkillsPromptForRun to prefer entries over cached snapshots when entries are provided
  • Skills are already synced from the agent workspace to the sandbox workspace by resolveSandboxContext, so loading from the sandbox workspace directory correctly picks up the synced skills

The change ensures that the <location> paths in skill prompts point to files within the sandbox root, preventing "Path escapes sandbox root" errors when the Read tool is used.

Confidence Score: 4/5

  • This PR is safe to merge with minor considerations
  • The implementation correctly fixes the sandbox path escape issue. The logic is sound: skills are synced to the sandbox workspace before being loaded, and the prompt is built with paths relative to the sandbox root. Tests verify the new behavior. Score is 4 (not 5) because sync failures are logged but non-blocking, which could lead to missing skills in edge cases
  • No files require special attention - the implementation is consistent across both attempt.ts and compact.ts

Last reviewed commit: 2c91f47

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Feb 27, 2026
@mudrii

This comment was marked as spam.

@mudrii

This comment was marked as spam.

@jalehman jalehman self-assigned this Mar 3, 2026
@jalehman

jalehman commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for fixing the sandbox <location> path issue — the path rewriting approach is directionally correct.

I found a regression: in sandbox mode, the new code path rebuilds prompt/env from runtime entries and drops skillsSnapshot constraints (skillFilter/eligibility), which can widen skill visibility and env overrides beyond what the session intended.

Two related findings:

  1. Snapshot filtering bypass — attempt.ts and compact.ts set skillsSnapshot: undefined when sandboxed, so resolveSkillsPromptForRun rebuilds from raw entries without the skillFilter/eligibility constraints that session-updates.ts applied when creating the snapshot.

  2. Env override scope widened — sandbox mode calls applySkillEnvOverrides({ skills: skillEntries }) instead of applySkillEnvOverridesFromSnapshot, so skills excluded by the snapshot filter can still inject env vars.

Suggested fix: In sandbox mode, filter skillEntries to snapshot skill names before passing to resolveSkillsPromptForRun + applySkillEnvOverrides, or extend the call path to accept and apply the same skillFilter/eligibility constraints. This preserves the sandbox path rewriting while maintaining snapshot semantics.

A regression test covering sandbox + restrictive skillFilter → asserting only snapshot-allowed skills in prompt/env would be great to add.

@jalehman

Copy link
Copy Markdown
Contributor

Closing as stale. Please reopen with an updated branch if you still want to pursue this work.

@jalehman jalehman closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Sandbox skill <location> in system prompt uses host path instead of sandbox path

3 participants