From 3627f4777fae1852b33d6c80853540776573255a Mon Sep 17 00:00:00 2001 From: Gal Zahavi <38544478+galz10@users.noreply.github.com> Date: Tue, 5 May 2026 14:26:16 -0700 Subject: [PATCH] fix(core): allow redirection in YOLO and AUTO_EDIT modes without sandboxing (#26542) --- .../core/src/policy/policy-engine.test.ts | 24 +++++++++++++++++++ packages/core/src/policy/policy-engine.ts | 9 ++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/core/src/policy/policy-engine.test.ts b/packages/core/src/policy/policy-engine.test.ts index 0769c7363d..5d68b45035 100644 --- a/packages/core/src/policy/policy-engine.test.ts +++ b/packages/core/src/policy/policy-engine.test.ts @@ -1898,6 +1898,30 @@ describe('PolicyEngine', () => { expect(result.decision).toBe(PolicyDecision.ALLOW); }); + it('should NOT downgrade to ASK_USER for redirected commands in YOLO mode even without sandbox', async () => { + const rules: PolicyRule[] = [ + { + toolName: 'run_shell_command', + decision: PolicyDecision.ALLOW, + priority: 10, + }, + ]; + + engine = new PolicyEngine({ + rules, + approvalMode: ApprovalMode.YOLO, + sandboxManager: new NoopSandboxManager(), + }); + + const command = 'npm test 2>&1 | tail -80'; + const { decision } = await engine.check( + { name: 'run_shell_command', args: { command } }, + undefined, + ); + + expect(decision).toBe(PolicyDecision.ALLOW); + }); + it('should return ALLOW in YOLO mode even if shell command parsing fails', async () => { const { splitCommands } = await import('../utils/shell-utils.js'); const rules: PolicyRule[] = [ diff --git a/packages/core/src/policy/policy-engine.ts b/packages/core/src/policy/policy-engine.ts index 01f6b75fa6..a3b9aa0992 100644 --- a/packages/core/src/policy/policy-engine.ts +++ b/packages/core/src/policy/policy-engine.ts @@ -288,12 +288,11 @@ export class PolicyEngine { if (allowRedirection) return false; if (!hasRedirection(command)) return false; - // Do not downgrade (do not ask user) if sandboxing is enabled and in AUTO_EDIT or YOLO - const sandboxEnabled = !(this.sandboxManager instanceof NoopSandboxManager); + // Do not downgrade (do not ask user) if in AUTO_EDIT or YOLO mode. + // These modes trust the agent's actions (YOLO) or specific task (AUTO_EDIT). if ( - sandboxEnabled && - (this.approvalMode === ApprovalMode.AUTO_EDIT || - this.approvalMode === ApprovalMode.YOLO) + this.approvalMode === ApprovalMode.AUTO_EDIT || + this.approvalMode === ApprovalMode.YOLO ) { return false; }