run_shell_command tool allows the Gemini model to execute commands directly on your system’s shell, enabling interaction with your environment beyond simple file edits.
Overview
Commands execute using platform-specific shells:- Windows:
powershell.exe -NoProfile -Command - macOS/Linux:
bash -c
GEMINI_CLI=1 environment variable in all subprocess environments, allowing scripts to detect they’re running within the Gemini CLI.
Parameters
The exact shell command to execute
Brief description shown to the user for confirmation
Absolute or relative path from workspace root where the command runs
Whether to move the process to the background immediately after starting
Return Value
The tool returns a JSON object containing:Configuration
Configure shell behavior in yoursettings.json or use /settings command.
Interactive Shell
Enable interactive commands with pseudo-terminal support:Uses
node-pty for real-time interaction. Enables support for interactive commands like vim, nano, htop, and git rebase -i.Preserves ANSI colors in output. Only applies when
enableInteractiveShell is enabled.Custom pager for shell output. Only applies when
enableInteractiveShell is enabled.Seconds to wait for output before killing the process
When an interactive command is running, press
Tab to focus on the interactive shell. Terminal output, including complex TUIs, will be rendered correctly.Command Restrictions
Control which commands can be executed using allowlist and blocklist settings.Allowlist Specific Commands
Restrict to onlygit and npm commands:
- ✅
git status- Allowed - ✅
npm install- Allowed - ❌
ls -l- Blocked
Block Specific Commands
Allow all commands exceptrm:
- ❌
rm -rf /- Blocked - ✅
git status- Allowed - ✅
npm install- Allowed
Command Validation
The validation logic provides security and flexibility:-
Command chaining disabled: Commands chained with
&&,||, or;are split and validated separately. If any part is disallowed, the entire command is blocked. -
Prefix matching: Allowing
gitpermitsgit status,git log, etc. -
Blocklist precedence:
tools.excludeis checked first. Blocked commands are denied even if allowed intools.core.
Use Cases
Build Scripts
Run project builds and compilation tasks
Test Suites
Execute test runners and validation scripts
Version Control
Initialize and manage Git repositories
Dependencies
Install and update project dependencies
Dev Servers
Start development servers and watchers
Database Tasks
Run migrations and database scripts
Examples
Running Tests
Starting a Dev Server
Git Operations
Security Considerations
- Always check
Stderr,Error, andExit Codefields to determine success - Background processes continue running after the tool returns
- The
Background PIDsfield contains process IDs for background tasks - Environment variables can be restricted via sanitization policies
Environment Variables
Automatic Environment Variable:Next Steps
Shell Commands Tutorial
Learn practical shell command patterns
Sandboxing
Isolate command execution for enhanced security