google-gemini/gemini-cli · error · Error

Security configuration not loaded. Cannot verify shell comma

Error message

Security configuration not loaded. Cannot verify shell command permissions for '${this.commandName}'. Aborting.

What it means

Thrown by ShellProcessor.processString() when the prompt contains a shell injection trigger ('!{') but context.services.agentContext?.config is undefined. The processor refuses to run shell commands without the security/policy config because it must call config.getPolicyEngine().check() to authorize each command.

Source

Thrown at packages/cli/src/services/prompt-processors/shellProcessor.ts:79

      this.processString(text, context),
    );
  }

  private async processString(
    prompt: string,
    context: CommandContext,
  ): Promise<PromptPipelineContent> {
    const userArgsRaw = context.invocation?.args || '';

    if (!prompt.includes(SHELL_INJECTION_TRIGGER)) {
      return [
        { text: prompt.replaceAll(SHORTHAND_ARGS_PLACEHOLDER, userArgsRaw) },
      ];
    }

    const config = context.services.agentContext?.config;
    if (!config) {
      throw new Error(
        `Security configuration not loaded. Cannot verify shell command permissions for '${this.commandName}'. Aborting.`,
      );
    }

    const injections = extractInjections(
      prompt,
      SHELL_INJECTION_TRIGGER,
      this.commandName,
    );

    // If extractInjections found no closed blocks (and didn't throw), treat as raw.
    if (injections.length === 0) {
      return [
        { text: prompt.replaceAll(SHORTHAND_ARGS_PLACEHOLDER, userArgsRaw) },
      ];
    }

    const { shell } = getShellConfiguration();

View on GitHub (pinned to 5024443c72)

Solutions

  1. Ensure the CommandContext passed to the command/processor includes services.agentContext.config (a loaded Config instance).
  2. Only invoke commands that use '!{...}' after the agent/config bootstrap is complete.
  3. If shell injection is not needed, remove the '!{...}' from the prompt so the processor skips the config check entirely.

Example fix

// before
const ctx = { services: { agentContext: undefined } };
await shellProcessor.process(prompt, ctx);
// after
const ctx = { services: { agentContext: { config: loadedConfig } } };
await shellProcessor.process(prompt, ctx);
Defensive patterns

Strategy: validation

Validate before calling

function shellProcessorReady(context: CommandContext): boolean {
  return !!context.services?.agentContext?.config &&
    typeof context.services.agentContext.config.getPolicyEngine === 'function';
}

Type guard

function hasConfig(ctx: { services?: { agentContext?: { config?: unknown } } }): ctx is { services: { agentContext: { config: Config } } } {
  return !!ctx.services?.agentContext?.config;
}

Try / catch

try {
  await shellProcessor.process(prompt, ctx);
} catch (e) {
  if (e instanceof Error && /Security configuration not loaded/.test(e.message)) {
    // wire ctx.services.agentContext.config before invoking commands with !{...}
  }
  throw e;
}

Prevention

When it happens

Trigger: A command containing '!{...}' is processed but the CommandContext has no agentContext (or agentContext.config is unset), so the config lookup returns undefined.

Common situations: Programmatically invoking a ShellProcessor-bound command without wiring services.agentContext.config; a custom integration that constructs CommandContext incompletely; running a shell-injection command before the agent context is initialized.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/1de8f5d184396fe8. Report an issue: GitHub.