fix (sandbox/prompts): align workspace guidance with container workdir

This commit is contained in:
Vignesh Natarajan
2026-02-14 20:20:29 -08:00
parent f29567b436
commit 2bf330777f
5 changed files with 27 additions and 3 deletions

View File

@@ -199,6 +199,7 @@ export function buildAgentSystemPrompt(params: {
sandboxInfo?: {
enabled: boolean;
workspaceDir?: string;
containerWorkspaceDir?: string;
workspaceAccess?: "none" | "ro" | "rw";
agentWorkspaceMount?: string;
browserBridgeUrl?: string;
@@ -348,6 +349,15 @@ export function buildAgentSystemPrompt(params: {
const messageChannelOptions = listDeliverableMessageChannels().join("|");
const promptMode = params.promptMode ?? "full";
const isMinimal = promptMode === "minimal" || promptMode === "none";
const sandboxContainerWorkspace = params.sandboxInfo?.containerWorkspaceDir?.trim();
const displayWorkspaceDir =
params.sandboxInfo?.enabled && sandboxContainerWorkspace
? sandboxContainerWorkspace
: params.workspaceDir;
const workspaceGuidance =
params.sandboxInfo?.enabled && sandboxContainerWorkspace
? `For read/write/edit/apply_patch, file paths resolve against host workspace: ${params.workspaceDir}. Prefer relative paths so both sandboxed exec and file tools work consistently.`
: "Treat this directory as the single global workspace for file operations unless explicitly instructed otherwise.";
const safetySection = [
"## Safety",
"You have no independent goals: do not pursue self-preservation, replication, resource acquisition, or power-seeking; avoid long-term plans beyond the user's request.",
@@ -450,8 +460,8 @@ export function buildAgentSystemPrompt(params: {
? "If you need the current date, time, or day of week, run session_status (📊 session_status)."
: "",
"## Workspace",
`Your working directory is: ${params.workspaceDir}`,
"Treat this directory as the single global workspace for file operations unless explicitly instructed otherwise.",
`Your working directory is: ${displayWorkspaceDir}`,
workspaceGuidance,
...workspaceNotes,
"",
...docsSection,
@@ -461,8 +471,11 @@ export function buildAgentSystemPrompt(params: {
"You are running in a sandboxed runtime (tools execute in Docker).",
"Some tools may be unavailable due to sandbox policy.",
"Sub-agents stay sandboxed (no elevated/host access). Need outside-sandbox read/write? Don't spawn; ask first.",
params.sandboxInfo.containerWorkspaceDir
? `Sandbox container workdir: ${params.sandboxInfo.containerWorkspaceDir}`
: "",
params.sandboxInfo.workspaceDir
? `Sandbox workspace: ${params.sandboxInfo.workspaceDir}`
? `Sandbox host workspace: ${params.sandboxInfo.workspaceDir}`
: "",
params.sandboxInfo.workspaceAccess
? `Agent workspace access: ${params.sandboxInfo.workspaceAccess}${