{"record":{"id":"0cb6aefce3392c0f","repo":"google-gemini/gemini-cli","slug":"this-commandname-cannot-be-run-blocked-command","errorCode":null,"errorMessage":"${this.commandName} cannot be run. Blocked command: \"${command}\". Reason: Blocked by policy.","messagePattern":"(.+?) cannot be run\\. Blocked command: \"(.+?)\"\\. Reason: Blocked by policy\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/services/prompt-processors/shellProcessor.ts","lineNumber":136,"sourceCode":"      const command = injection.resolvedCommand;\n\n      if (!command) continue;\n\n      if (context.session.sessionShellAllowlist?.has(command)) {\n        continue;\n      }\n\n      // Security check on the final, escaped command string.\n      const { decision } = await config.getPolicyEngine().check(\n        {\n          name: 'run_shell_command',\n          args: { command },\n        },\n        undefined,\n      );\n\n      if (decision === PolicyDecision.DENY) {\n        throw new Error(\n          `${this.commandName} cannot be run. Blocked command: \"${command}\". Reason: Blocked by policy.`,\n        );\n      } else if (decision === PolicyDecision.ASK_USER) {\n        commandsToConfirm.add(command);\n      }\n    }\n\n    // Handle confirmation requirements.\n    if (commandsToConfirm.size > 0) {\n      throw new ConfirmationRequiredError(\n        'Shell command confirmation required',\n        Array.from(commandsToConfirm),\n      );\n    }\n\n    let processedPrompt = '';\n    let lastIndex = 0;\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/services/prompt-processors/shellProcessor.ts#L118-L154","documentation":"Thrown by ShellProcessor when config.getPolicyEngine().check() returns PolicyDecision.DENY for a resolved shell command. The command matched a deny rule in the security policy and is blocked outright (distinct from ASK_USER, which requests confirmation).","triggerScenarios":"A '!{...}' injection resolves to a command that the policy engine denies (e.g. matches a blocked command pattern / denylist) and is not on the session shell allowlist.","commonSituations":"The resolved command matches a deny entry in settings security rules; a corporate/managed policy blocks the command; the command string after {{args}} substitution fell into a denied pattern.","solutions":["Inspect the denied command in the message and reword the injection so it does not match a deny rule.","Add the exact command to the session shell allowlist (session.sessionShellAllowlist) if it is safe and intended.","Review the security policy in settings.json and adjust deny rules if the block is overly broad.","Avoid passing {{args}} that expand the command into a denied form."],"exampleFix":"// before — policy denies rm\ncleanup !{rm -rf ./build}\n// after — allowlisted safe alternative\ncleanup !{./scripts/clean-build.sh}","handlingStrategy":"try-catch","validationCode":"async function isAllowed(command: string, config: Config): Promise<boolean> {\n  const { decision } = await config.getPolicyEngine().check(\n    { name: 'run_shell_command', args: { command } }, undefined);\n  return decision !== PolicyDecision.DENY;\n}","typeGuard":"function isDenied(decision: PolicyDecision): boolean {\n  return decision === PolicyDecision.DENY;\n}","tryCatchPattern":"try {\n  await shellProcessor.process(prompt, ctx);\n} catch (e) {\n  if (e instanceof Error && /Blocked by policy/.test(e.message)) {\n    // reword the command or add it to the allowlist/policy\n  }\n  throw e;\n}","preventionTips":["Review deny rules in the security policy before writing shell injections.","Add trusted commands to the session shell allowlist or an allow policy rule.","Avoid {{args}} substitutions that expand a command into a denied pattern."],"tags":["shell","policy","security","permissions","deny"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}