{"record":{"id":"ad595dbd953ff1fc","repo":"google-gemini/gemini-cli","slug":"agent-execution-blocked","errorCode":"AGENT_EXECUTION_BLOCKED","errorMessage":"${event.value.systemMessage?.trim() || event.value.reason}","messagePattern":"\\$\\{event\\.value\\.systemMessage\\?\\.trim\\(\\) \\|\\| event\\.value\\.reason\\}","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/event-translator.ts","lineNumber":215,"sourceCode":"      ensureStreamStart(state, out);\n      out.push(\n        makeEvent('agent_end', state, {\n          reason: 'completed',\n          data: {\n            message: event.value.systemMessage?.trim() || event.value.reason,\n          },\n        }),\n      );\n      break;\n\n    case GeminiEventType.AgentExecutionBlocked:\n      ensureStreamStart(state, out);\n      out.push(\n        makeEvent('error', state, {\n          status: 'PERMISSION_DENIED',\n          message: event.value.systemMessage?.trim() || event.value.reason,\n          fatal: false,\n          _meta: { code: 'AGENT_EXECUTION_BLOCKED' },\n        }),\n      );\n      break;\n\n    case GeminiEventType.InvalidStream:\n      ensureStreamStart(state, out);\n      out.push(\n        makeEvent('error', state, {\n          status: 'INTERNAL',\n          message:\n            event.value?.message?.trim() ||\n            'Invalid stream received from model',\n          fatal: true,\n          _meta: {\n            code: 'INVALID_STREAM',\n            errorType: event.value?.type,\n            rawMessage: event.value?.message,\n          },","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/core/src/agent/event-translator.ts#L197-L233","documentation":"AGENT_EXECUTION_BLOCKED is emitted as a non-fatal PERMISSION_DENIED error when the model attempted an action blocked by the agent's policy/sandbox. The message is the server's systemMessage (preferred) or its reason string.","triggerScenarios":"translateEvent() receives GeminiEventType.AgentExecutionBlocked -> pushes makeEvent('error', { status:'PERMISSION_DENIED', message: event.value.systemMessage?.trim() || event.value.reason, fatal:false, _meta.code:'AGENT_EXECUTION_BLOCKED' }).","commonSituations":"Agent tries to run a shell command, write outside the workspace, or call a disallowed tool; Code Assist server policy rejects the action; sandbox tool-allowlist is too narrow.","solutions":["Read event.value.systemMessage for the exact blocked action and grant that specific permission.","Broaden the tool/policy allowlist for the session (e.g. allow the path the agent needs).","If the action should stay blocked, steer the prompt away from it."],"exampleFix":"// before\npolicies: [policy.denyShell()]\n// after\npolicies: [policy.allowShell({ commands: ['git','npm'] })]","handlingStrategy":"validation","validationCode":"// before running, confirm the action set the agent may need is allowed\nconst needed = ['shell:git', 'fs:write:src/**'];\nfor (const n of needed) if (!policy.allows(n)) policy.grant(n);","typeGuard":"function isExecutionBlocked(ev: unknown): boolean {\n  return typeof ev === 'object' && ev !== null && (ev as any)._meta?.code === 'AGENT_EXECUTION_BLOCKED';\n}","tryCatchPattern":"if (ev.type === 'error' && ev._meta?.code === 'AGENT_EXECUTION_BLOCKED') {\n  // read ev.message, grant the specific permission, then resume the session\n}","preventionTips":["Scope the policy to the actions the task actually needs rather than allow_all.","Surface systemMessage to the user so they can approve the blocked action."],"tags":["permissions","sandbox","agent-policy","gemini","typescript"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}