#4022: fix: apply sandbox tools denials in /tools/invoke
gateway
agents
Cluster:
Sandbox Enhancements and Fixes
I discussed this issue with @steipete before opening the PR. This change ensures that the `/tools/invoke` endpoint applies the correct sandbox tool denials.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR introduces a `sendForbidden` helper and updates the `/tools/invoke` gateway handler to enforce sandbox tool denials before continuing with normal tool-policy resolution and execution.
This aligns `/tools/invoke` with the sandbox runtime/tool-policy system in `src/agents/sandbox/*`, ensuring sandboxed sessions can’t invoke blocked tools even if they reach the endpoint.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge, but double-check sandbox session key canonicalization to avoid policy gaps.
- Changes are small and targeted, but the sandbox decision depends on session key normalization; any mismatch between raw and canonical keys could allow unintended tool access or inconsistent behavior.
- src/gateway/tools-invoke-http.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#7851: feat: secure sandbox defaults for new installs
by ichbinlucaskim · 2026-02-03
78.0%
#16922: fix: remove incorrect sandbox file tool guidance
by carrotRakko · 2026-02-15
77.4%
#23811: Config: fail closed when exec host=sandbox but sandbox mode is off
by bmendonca3 · 2026-02-22
77.1%
#3967: fix(sandbox): correct workspace prompt path
by sweepies · 2026-01-29
76.7%
#11497: feat(exec): inject agent identity env vars for subagents
by NOVA-Openclaw · 2026-02-07
76.5%
#3647: fix: sanitize tool arguments in session history
by nhangen · 2026-01-29
76.3%
#5952: feat(tools): add fs.restrictToWorkspace config option
by reubence · 2026-02-01
75.9%
#7874: docs: add public/untrusted agent profile
by ichbinlucaskim · 2026-02-03
75.8%
#4057: fix: sanitize tool call IDs for Azure OpenAI
by wangchuan3533 · 2026-01-29
75.7%
#4226: Fix/sandbox containerworkdir rw access
by ozgur-polat · 2026-01-29
75.4%