Read and write Google Sheets from a sandbox with a service account
How we gave an agent hands-on access to Google Sheets without an OAuth dance for every user — OpenSandbox on a Google Cloud VM, a service-account key mounted read-only, and a reusable skill that tells every agent how to use it.

Spreadsheets are where a lot of a company’s operational truth lives — and where a lot of copy-paste work happens. This guide gives a Harnesst agent hands-on access to Google Sheets without an OAuth dance for every user: the agent runs Python in a sandbox, and the sandbox carries a service-account key that Google Sheets trusts.
You’ll end up with an agent you can ask things like “append these three rows to the Leads sheet” or “summarize the Q3 tab”, and a reusable skill that tells every agent how to do it.
The shape of the solution
┌──────────────────────── Google Cloud VM ────────────────────────┐
│ │
│ harnesst backend + web (docker compose) │
│ │ Settings → Sandboxes: OpenSandbox @ localhost:8080 │
│ ▼ │
│ OpenSandbox server ──▶ sandbox container (python:3.12-slim) │
│ /secrets/sheets-sa.json (read-only) │
│ pip: gspread, google-auth │
└────────────────────────────────┬────────────────────────────────┘
│ HTTPS, signed as the service account
▼
Google Sheets API ──▶ your spreadsheet
(shared with the SA)Three ideas carry the whole thing:
- A service account is a Google identity with its own email. Share a spreadsheet with that email and it can read and write it — no user consent screen, no token refresh.
- The key file lives on the VM and is bind-mounted read-only into every sandbox the workspace’s OpenSandbox creates. The agent never sees the key in chat; its code just opens a path.
- Harnesst only orchestrates: the agent’s Python runs in the sandbox, the credentials never touch the LLM.
Before you start
- A Google Cloud project where you can create service accounts and a Compute Engine VM
- A Harnesst deployment you can administer (workspace admin), reachable from that VM — the simplest setup, used here, is the whole stack on the same VM with
docker compose(see VM / Docker host) - Docker on the VM
Why the same VM? OpenSandbox mounts a host path into sandbox containers — the host being the machine that runs the OpenSandbox server. Harnesst also checks that the path exists on its own host before asking for the mount (_parse_volume_mounts in the OpenSandbox provider skips paths it can’t find). With everything on one VM the two hosts are the same machine and both checks pass. If you split them, the path must exist on both.
Step 1 — Create the service account and key
export PROJECT_ID=your-project-id
gcloud config set project $PROJECT_ID
gcloud services enable sheets.googleapis.com drive.googleapis.com
gcloud iam service-accounts create harnesst-sheets \
--display-name "harnesst Sheets agent"
gcloud iam service-accounts keys create sheets-sa.json \
--iam-account harnesst-sheets@$PROJECT_ID.iam.gserviceaccount.comThe service account needs no IAM roles for this — access to a spreadsheet is granted by sharing the spreadsheet, not by project permissions. (The Drive API is enabled so gspread can open spreadsheets by title; opening by URL or key only needs Sheets.)
Step 2 — Share the spreadsheet with the service account
Open the spreadsheet in Google Sheets → Share → paste harnesst-sheets@your-project-id.iam.gserviceaccount.com → Editor (or Viewer for read-only agents) → uncheck “Notify” → Share.
Do this for every spreadsheet the agent should touch. Everything else stays invisible to it, which is exactly the blast radius you want.
Step 3 — Put the key on the VM
sudo mkdir -p /srv/harnesst/secrets
sudo cp sheets-sa.json /srv/harnesst/secrets/sheets-sa.json
sudo chmod 0444 /srv/harnesst/secrets/sheets-sa.json
rm sheets-sa.json # don't leave copies lying aroundStep 4 — Run OpenSandbox on the VM
OpenSandbox is the open-source sandbox runtime Harnesst talks to. Its server manages sandbox containers through the VM’s Docker daemon and listens on port 8080 by default. A minimal, single-host configuration (write it to ~/.sandbox.toml, or start from uvx opensandbox-server init-config ~/.sandbox.toml --example docker and edit):
[runtime]
type = "docker"
execd_image = "opensandbox/execd:v1.0"
[server]
host = "0.0.0.0"
port = 8080
api_key = "replace-with-a-long-random-string" # clients send it as OPEN-SANDBOX-API-KEY
[docker]
network_mode = "bridge" # sandboxes get outbound network → Google APIs
[storage]
# Host paths that sandboxes may bind-mount. Empty = all host mounts rejected.
allowed_host_paths = ["/srv/harnesst/secrets"]Then start it (an example — pin versions and run it under systemd or in a container for real deployments):
uvx opensandbox-serverTwo settings matter for this tutorial: the api_key (you’ll paste it into Harnesst) and allowed_host_paths, which must list the prefix of the directory you want to mount — OpenSandbox refuses host mounts outside it, secure by default. If you deploy Harnesst with docker compose on the same VM, the backend reaches the server at host.docker.internal:8080 (Linux: add extra_hosts: ["host.docker.internal:host-gateway"] to the backend service) or at the VM’s private IP. Keep port 8080 closed to the internet — only the backend needs it.
The exact execd_image tag, TOML layout and CLI flags are those of the OpenSandbox release you install — check the project’s server configuration reference for your version before copying the snippet above.
Step 5 — Register the sandbox in Harnesst
Sandboxes are configured in the UI, per workspace. In Harnesst, open Settings → Sandboxes → Add sandbox and pick OpenSandbox:

| Field | Value |
|---|---|
| Name | Sheets lab |
| Domain | host.docker.internal:8080 (or the VM’s private IP + port) |
| API key | the api_key from ~/.sandbox.toml |
| Default packages | gspread, google-auth |
| Timeout (seconds) | leave the default |
| Default image | python:3.12-slim (default) |
| Volume mounts (optional) | /srv/harnesst/secrets:/secrets:ro |
| Use server proxy | on |
Default packages are pip installed into every fresh sandbox. If cold starts matter, build an image with them preinstalled instead and put it in Default image — the slides case study shows how.
The mount syntax is host_path:sandbox_path[:ro]. Always use :ro for credentials: nothing the agent runs should be able to alter the key.
Save. The sandbox row now appears under Settings → Sandboxes; the backend probes it before every run of an agent bound to it, and blocks the composer with a clear message if it’s unreachable. See Sandbox — Setup for the other providers and knobs.
Step 6 — Give an agent the sandbox
Create an agent (Agents → New agent) or edit one, then in the tools panel click Add tool. Below the MCP servers, the dialog lists the workspace’s sandboxes — add Sheets lab.

That’s the whole “enable code execution” step. From the next message on, the agent has the sandbox toolset (execute, read_file, write_file, edit_file, ls, glob, grep); the sandbox is opened at the start of each run and reused across turns of the thread. See Using the sandbox.
Step 7 — Teach it the procedure with a skill
You could explain the key path and the gspread incantation in the agent’s instructions. A skill is the better home: it’s reusable across agents, versioned, and only loaded when the request is about spreadsheets.
Open Skills → New skill and fill in:
- Name:
google-sheets - Description:
Read, append to and summarize Google Sheets with the workspace service account. Use when the user mentions a spreadsheet, a sheet, a tab or a Google Sheets URL. - Instructions:
# When to use
Any request that reads or changes a Google Sheet. The sandbox has `gspread`
and `google-auth` installed and a service-account key at
`/secrets/sheets-sa.json`. The spreadsheet must already be shared with
the service-account email — if a call fails with 403, say so and give the
user the email to share with (it is in the key file's `client_email`).
# Steps
1. Identify the spreadsheet (URL, key or exact title) and the worksheet
(tab). Ask if ambiguous; never guess a tab name.
2. Write a small script to `/tmp/sheets_task.py` and run it with
`python /tmp/sheets_task.py`. Always start from:
```python
import gspread
gc = gspread.service_account(filename="/secrets/sheets-sa.json")
sh = gc.open_by_url(URL) # or gc.open_by_key(KEY)
ws = sh.worksheet(TAB) # or sh.sheet1
```
3. Reading: `ws.get_all_records()` for tables with a header row,
`ws.get("A1:D20")` for ranges. Summarize in prose; never dump more
than 20 rows unless asked.
4. Writing: `ws.append_rows(rows, value_input_option="USER_ENTERED")` for
new rows; `ws.update("B2:B10", values)` for edits. Before writing,
show the exact rows or cells you are about to change and wait for a
confirmation, unless the user already listed them explicitly.
5. After a write, read back the affected range and report what changed.
# Rules
- Never print the contents of `/secrets/sheets-sa.json`.
- Never create or delete spreadsheets; only worksheets inside one you
were given, and only when asked.
Click Create skill. A skill written in the app is one SKILL.md and runs on any agent; the model writes the actual script each time from the recipe above. If you’d rather ship a tested scripts/sheets.py alongside the instructions (a CLI like python sheets.py append --url … --tab Leads --rows-json …), keep the skill in a Git repository and connect it under Skills → Sources — scripts and reference files come from repositories, so they’re reviewed and versioned. The slides case study walks through that flow.
Now enable the skill on the agent: open the agent → Edit → Add skill → google-sheets → Save changes. It carries no CODE EXECUTION badge (no scripts, so it runs on any agent), and the agent’s system prompt will list it with the absolute path of its SKILL.md. See Skills.

Step 8 — Try it
Open Test in chat and paste a spreadsheet URL:
In https://docs.google.com/spreadsheets/d/1AbC…/edit, tab "Leads", append:
Northwind Logistics, Maria Gomez, maria@northwind.example, Inbound, 2026-09-23Watch the chain of thought: the agent reads SKILL.md (read_file), writes /tmp/sheets_task.py, runs it (execute), and reports the row it appended.

Other things that just work from here:
- “Read the Q3 tab and tell me which reps are below 80% of quota.”
- “Add a column D ‘Owner’ and fill it from the mapping in tab Owners.”
- “Every Monday, summarize new rows since last week” — make it a Trigger with those instructions; the run executes as the trigger’s owner and the sandbox is opened for it like any other run.
Security notes
- The key is visible to any agent bound to that sandbox. Every sandbox created from the Sheets lab row gets
/secretsmounted. Bind that sandbox only to agents you’d trust with the spreadsheets the service account can see, and create a second sandbox row (or a second service account) for agents that need less. - Mount read-only (
:ro). It stops a prompt-injected script from tampering with the key; it doesn’t stop it from reading the key — which is why the rule “never print the key” is in the skill and why the next point matters. - Scope the identity, not the tool. Share only the spreadsheets the agent needs, as Viewer where writing isn’t required. Prefer one service account per purpose over one master account.
- Keep the file off the network. Port 8080 (OpenSandbox) should be reachable from the backend only. Combine with the agent’s permissions so only the right teammates can chat with the sheet-writing agent, and set MCP tools with side effects to Needs approval where the run is interactive.
- Rotate.
gcloud iam service-accounts keys createa new key, replace the file on the VM (same path — new sandboxes pick it up, running ones keep the old file until they expire), thengcloud iam service-accounts keys deletethe old one.
Where to go next
- Slide decks with a skill from GitHub — a custom sandbox image and a skill with scripts, synced from a repository
- Sandbox — Security — isolation model, mounts and timeouts across providers
- Triggers — run the spreadsheet agent on a schedule