Integration: Gemini CLI
How do I secure Gemini CLI?
Updated
Short answer
Run Gemini CLI in a sandbox, turn on trusted folders, lock YOLO mode off with admin settings, and check every action before it runs. Google's docs say sandboxing reduces but doesn't eliminate risk, trusted folders are off by default, and project-level policies don't work yet. Harden AIF checks each Gemini CLI action on the developer's machine before it executes, and blocks the dangerous ones.
What Gemini CLI can do on a developer's machine#
- Run shell commands. Google's shell tool docs say it lets the model "execute commands directly on your system's shell".
- Write and edit files in the project and beyond.
- Call MCP server tools and fetch web content, which can carry instructions the model then follows.
- In YOLO mode, approve every one of those tools automatically.
What Gemini CLI's own controls do, and what they miss#
- Approval modes decide what runs without asking. Google describes YOLO as auto-approving all tools, to "use with extreme caution". Admins can switch it off with
security.disableYoloModeandadmin.secureModeEnabled. - The sandbox (Docker, Podman or macOS Seatbelt) isolates shell commands and file changes once you enable it. The docs say sandboxing "reduces but doesn't eliminate all risks".
- Trusted folders run untrusted projects in a restricted safe mode. The feature is disabled by default, and a
--skip-trustflag skips it. - The policy engine allows, denies or asks per tool call. Shell rules match on how the command string starts, and the docs say project-level policies are "currently non-functional".
- The BeforeTool hook "Fires before a tool is invoked" and can deny the call. It runs whatever check you write.
What Harden AIF checks before each Gemini CLI action#
AIF is a separate service on the developer's machine. Gemini CLI calls it through its hooks before each action runs, so the check sits outside the agent and its context window. For each pending action, it:
- parses the command into a syntax tree and follows each value from its source to where it ends up, so a secret headed for a network call gets blocked however the command is written;
- judges secrets by their content, not their file name;
- checks destructive commands (recursive deletes, force-pushes to the default branch, piping
curlinto a shell, disk wipes) against where they actually run; - decodes base64 and hex before it decides, and sends dynamic code it can't resolve to a human;
- fails closed: if the check can't run, the action doesn't run.
When it blocks, the agent gets the reason and can retry a safe way. Every decision is recorded, and you can export the records to your SIEM.
How to set up Harden for Gemini CLI#
- Install AIF with
curl -fsSL https://aif.harden.run/install.sh | sh, then open a new shell. - Run
aif status, andaif doctorif anything isn't ready. - Talk to a Harden engineer to connect Gemini CLI and validate the first protected run.
For a fleet, the enterprise setup guide covers the organization, enrollment profile, MDM push and pilot checks. Start in shadow mode, so your team sees what agents do before anything gets blocked.
FAQ
Questions about Gemini CLI
Is Gemini CLI's sandbox on by default?
You enable it. Google's docs describe Docker, Podman and macOS Seatbelt options and say sandboxing reduces but doesn't eliminate all risks. Turn it on, and check actions before they run as well.
Can I stop developers using YOLO mode in Gemini CLI?
Yes. The security.disableYoloMode setting disables it even if a flag enables it, and admin.secureModeEnabled also turns off the Always allow option.
Does Gemini CLI have a pre-execution hook?
Yes. The BeforeTool hook fires before a tool is invoked and can deny the call. Harden AIF checks each action at that point, on the developer's machine.