Gemini CLI defaults to running shell commands directly on your host machine, a risky behavior for teams letting agents touch unreviewed branches. A new guide from Sandscale details how to offload these operations to a secure sandbox using the Model Context Protocol (MCP). By configuring the settings.json file, developers can force the agent to call remote tools instead of executing npm install or test suites locally.

The Two-Path Configuration Strategy

The setup depends entirely on where Gemini CLI is running. For developers on laptops with a browser, the remote Streamable HTTP server at https://mcp.sandscale.dev/mcp is the way to go. This entry uses OAuth for authentication, meaning no secrets are stored in the config file. Each team member signs in as themselves, ensuring audit logs attribute actions to the correct human. Conversely, headless environments like cloud workspaces or SSH sessions cannot handle OAuth redirects. These machines require the local stdio server, invoked via sandscale mcp. This method relies on the CLI’s own sign-in mechanism, typically authenticated via sandscale login --device using a code approval flow on a separate device. This entry belongs in the user-specific ~/.gemini/settings.json, not the committed project file.

Critical Environment and Naming Pitfalls

Naming conventions in MCP servers are strict. Gemini CLI registers tools as mcp_{serverName}_{toolName}. The documentation warns against underscores in server names because the policy parser splits on the first underscore after mcp_. Using a name like sandscale_mcp will break tool resolution; stick to sandscale. Furthermore, Gemini CLI aggressively scrubs sensitive environment variables from inherited shells when launching stdio servers. Variables matching *KEY*, *TOKEN*, or *SECRET* are stripped. If you rely on SANDSCALE_API_KEY, you must explicitly pass it in the env block of the config, though the guide advises using personal sign-ins for better accountability in team settings.

Controlling Agent Autonomy

By default, Gemini CLI prompts for permission before running any MCP tool. You can automate this with "trust": true, but the guide recommends leaving this off for committed files to maintain security. Instead, use includeTools to whitelist only necessary functions like sandbox_run and sandbox_create. This limits the agent's surface area while allowing it to operate efficiently. The configuration also requires explicit instructions in GEMINI.md or AGENTS.md to tell the model when to use these tools. A sample snippet suggests running dependency installs and tests in the sandbox, starting one per task, and downloading outputs as files rather than pasting raw logs. Remember, these are requests; the includeTools list and confirmation prompts are the actual enforcement mechanisms.

Key Takeaways

  • Use httpUrl for laptop-based OAuth flows and command for headless stdio environments.
  • Never use underscores in MCP server names to avoid parsing errors in Gemini CLI.
  • Explicitly define includeTools to restrict agent capabilities rather than relying solely on prompt instructions.
  • Avoid passing API keys via environment variables; use personal device login for better audit trails.

The Bottom Line

Stop letting AI agents execute arbitrary shell commands on your primary development machine. Sandboxing via MCP is not just a security feature; it is the only way to scale agent usage across a team without chaos.