# Gemini CLI and MCP: a settings.json that gives the agent its own sandbox, for a team

> Gemini CLI reads MCP servers from settings.json. How a team adds Sandscale there so the agent's commands run on its own sandbox: the remote server for people at a laptop, the local stdio server on a headless agent machine, and the Gemini settings that decide what runs without asking.

Gemini CLI reads MCP servers from settings.json. How a team adds Sandscale there so the agent's commands run on its own sandbox: the remote server for people at a laptop, the local stdio server on a headless agent machine, and the Gemini settings that decide what runs without asking.

December 2, 2026 · 6 min read · The Sandscale team

Gemini CLI runs shell commands on the machine it runs on, like every coding agent. When a team starts letting it install dependencies and run test suites from branches nobody has read yet, the usual answer is to give those commands somewhere else to run. MCP is the simplest way to do that with Gemini CLI: add a server whose tools start a sandbox and run commands in it, and the agent calls those tools instead of touching your laptop.

This post sets that up with Sandscale for a team. The Gemini CLI details come from its [MCP server documentation](https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md), read on 2 December 2026. The Sandscale details come from the Sandscale CLI (1.4.1) help and the [Sandscale docs](https://sandscale.dev/docs/guides/connect-claude-chatgpt).

## Where Gemini CLI looks for MCP servers

Gemini CLI reads an `mcpServers` object from `settings.json`. There are two places that file lives:

- `~/.gemini/settings.json`, the user file, for one person’s machine.
- `.gemini/settings.json` in the project, which you can commit so everyone on the repository gets the same servers.

`gemini mcp add` writes to the project file by default; `-s user` writes to the user file. Each entry is either a stdio server (`command` and `args`), a Streamable HTTP server (`httpUrl`), or an SSE server (`url`).

Two Gemini details matter for the name you pick. Every MCP tool is registered as `mcp_{serverName}_{toolName}`, and the docs warn against underscores in server names because the policy parser splits on the first underscore after `mcp_`. Call the server `sandscale`, not `sandscale_mcp`.

## Two ways in, and who each is for

Sandscale’s [MCP server](https://sandscale.dev/sandboxes/mcp) comes in two forms. Which one a person uses depends on where Gemini CLI is running, more than on taste.

**At a laptop with a browser: the remote server.** Sandscale’s remote MCP server is at `https://mcp.sandscale.dev/mcp`, over Streamable HTTP. It signs in with OAuth, as the person, so the entry holds no secret:

```json
{
  "mcpServers": {
    "sandscale": {
      "httpUrl": "https://mcp.sandscale.dev/mcp"
    }
  }
}
```

Or from the shell:

```sh
gemini mcp add --transport http sandscale https://mcp.sandscale.dev/mcp
```

Gemini CLI’s docs say that when a server answers 401, the CLI discovers the OAuth endpoints from the server’s metadata, registers itself where the server supports it, opens a browser, and stores the tokens. Sandscale’s server publishes that metadata: its protected resource document names `auth.sandscale.dev` as the authorization server, and that server’s metadata lists a registration endpoint. Gemini CLI is not one of the clients `sandscale mcp connect` prints a snippet for, so this entry is one you write yourself, and the first sign-in happens in the browser when the server is first used (or with `/mcp auth`).

Because there is no secret in it, this is the entry to commit in `.gemini/settings.json`. Each person who opens the project signs in as themselves, and what their agent does is recorded as them.

**On a headless machine: the local stdio server.** Gemini CLI’s docs are direct about the limit of its OAuth support: it needs a local browser and a redirect to `localhost`, so it does not work in headless environments, over SSH without X11 forwarding, or in containers without a browser. That is exactly where many teams run agents: one cloud workspace per agent, reached over SSH.

There, use the stdio server that comes with the Sandscale CLI. Its help describes it as a stdio server with the command `sandscale` and the argument `mcp`:

```sh
gemini mcp add -s user sandscale sandscale mcp
```

which writes:

```json
{
  "mcpServers": {
    "sandscale": {
      "command": "sandscale",
      "args": ["mcp"]
    }
  }
}
```

The stdio server uses the CLI’s own sign-in on that machine. On a workspace without a browser, sign in with `sandscale login --device`: the CLI prints a short code and an address, and you approve it from your phone or laptop. Do this as the person who owns that agent, so the machine acts as them.

Put this one in the user file on the agent’s machine, not in the committed project file, because it depends on how that machine is signed in.

## The environment detail that will bite you

The Sandscale CLI uses `SANDSCALE_API_KEY` from the environment when it is set, and the person’s sign-in otherwise. Gemini CLI, when it starts a stdio server, removes variables that look sensitive from the inherited environment, including names matching `*KEY*`, `*TOKEN*` and `*SECRET*`. So an API key exported in your shell does not reach `sandscale mcp` unless you name it in the entry’s `env`:

```json
"env": { "SANDSCALE_API_KEY": "$SANDSCALE_API_KEY" }
```

For a team, we suggest not doing that on agent machines. A signed-in person is easier to reason about than a key: the audit log shows who it was, and `sandscale logout` revokes the session and deletes the local tokens when the machine is done. Keep API keys for unattended jobs that have no person behind them.

## What runs without asking

Gemini CLI asks before it runs an MCP tool unless you tell it not to. When it asks, you can proceed once, always allow that tool, always allow that server, or cancel. Three settings change that:

- `"trust": true` on the server skips every confirmation for it. The Gemini docs say to use it only for servers you completely control. Leave it off in a committed file.
- `includeTools` limits which of the server’s tools the agent sees at all; `excludeTools` removes some, and wins over `includeTools`.
- Gemini CLI’s policy engine can allow or deny MCP tools by their full names.

A reasonable starting point for the remote server is to show the agent only what it needs for a test run, and let it ask for the rest:

```json
{
  "mcpServers": {
    "sandscale": {
      "httpUrl": "https://mcp.sandscale.dev/mcp",
      "includeTools": ["sandbox_list", "sandbox_create", "sandbox_upload_file",
                       "sandbox_run", "sandbox_download_file", "sandbox_stop"]
    }
  }
}
```

Those names are from the remote server’s tool table in the Sandscale docs. The stdio server’s tools are the CLI’s API commands, with different names, so write its `includeTools` from what `/mcp list` shows you on that machine rather than copying this list.

Whatever Gemini asks, Sandscale applies its own checks on the other side: the call runs with the person’s permissions and plan limits, and changes go through the same API as everything else. A sandbox starts with networking off unless your organization’s policy allows a mode.

## What to tell the agent

The server gives Gemini CLI the tools. A line in `GEMINI.md` (or the `AGENTS.md` your team already shares) tells it when to use them:

```markdown
## Where commands run
- Run dependency installs and test suites in a Sandscale sandbox through the
  sandscale MCP tools, not in the local shell.
- Start one sandbox per task and stop it when the task is done.
- Bring back test output as a file and summarize it; do not paste whole logs.
```

Like any instruction file, this is a request, not enforcement. The `includeTools` list and the confirmation prompts are what actually limit the agent.

## Checklist

1. Committed `.gemini/settings.json`: the remote `httpUrl` entry, no secret, no `trust`.
2. On each headless agent machine: the stdio entry in `~/.gemini/settings.json`, signed in with `sandscale login --device` as the agent’s owner.
3. No API key passed through `env` unless the job has no person behind it.
4. An `includeTools` list per server, written from what the server actually lists.
5. A `GEMINI.md` section saying which commands go to the sandbox.

If you are running Gemini CLI on a workspace in the first place, our post on [running Gemini CLI headless in a cloud workspace](https://sandscale.dev/blog/gemini-cli-headless-in-a-cloud-workspace) covers that half. For the trade-offs between the two transports in general, see [MCP over stdio or Streamable HTTP](https://sandscale.dev/blog/mcp-stdio-vs-streamable-http).

**On this page**

1. Where Gemini CLI looks for MCP servers
2. Two ways in, and who each is for
3. The environment detail that will bite you
4. What runs without asking
5. What to tell the agent
6. Checklist

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [December 2, 2026 · **Auditing the MCP tool calls your team's coding agents make** · When Claude Code, Codex, Cursor or Gemini CLI call MCP tools, the record of what happened can live in three places: the client, the MCP server, and the system behind it. What each layer can see, which one to trust as the record, whether to keep arguments, and how to read Sandscale's audit log for agent calls from the CLI.](https://sandscale.dev/blog/auditing-mcp-tool-calls)
- [December 2, 2026 · **Device flow login on headless machines: signing a coding agent's machine in as a person** · An agent's cloud machine has no browser, so a CLI there cannot open a sign-in page. The OAuth device authorization grant (RFC 8628) solves that: a short code you approve on your phone or laptop. How it works, the one phishing risk to teach your team, and how to use sandscale login --device on each agent's machine.](https://sandscale.dev/blog/device-flow-login-on-headless-machines)

---
Source: https://sandscale.dev/blog/gemini-cli-mcp-config-remote-sandbox
