Gcloud

From Kilo-Org/kilo-marketplace · View interactive version

Gcloud is an AI agent skill from the GitHub repository Kilo-Org/kilo-marketplace. Interacts with Google Cloud services using the gcloud CLI safely and efficiently. Covers command validation, data reduction, safety guardrails with a denylist, and workflows for discovery and investigation. You MUST read this skill before invoking any gcloud command. Use when managing cloud resource

How to use this skill

Skill file

gcloud CLI Skill for AI Agents

This document provides essential guidelines and best practices for AI agents

interacting with the Google Cloud SDK (gcloud CLI). Following these rules is

critical to avoid hallucinated commands, flags, flag values, and positional

argument syntax, prevent destructive actions, and minimize context window usage.

Getting Started

1. Installation

If the gcloud executable is missing, refer to the official

Google Cloud CLI Installation Guide

to install it on your platform (Linux, macOS, Windows, etc.).

2. Authorization

Authenticate the CLI with Google Cloud. Choose the flow that matches your

running environment:

prompts to sign in.

browser (e.g. containers, remote SSH), append the --no-browser flag:

gcloud auth login --no-browser. Copy the URL, sign in on another machine,

and return the authentication code.

local applications or SDK libraries, set up ADC via `gcloud auth

application-default login (append --no-browser` for headless

environments).

directly using a JSON key file. Ideal for fully automated, background tasks

and pipelines: `gcloud auth activate-service-account

--key-file=path/to/key.json`. Note that some organizations may restrict

access to JSON key files for security reasons.

Agents)**: Leverage the human developer's existing user credentials to

assume a service account identity. Best for local development assistants to

avoid insecure private keys on human workstations: `gcloud config set

auth/impersonate_service_account SERVICE_ACCT_EMAIL`

Separation of Privilege (Critical): Both service account approaches ensure the

agent's permissions remain strictly distinct from the human user's wide access

limits (enforcing least privilege), and ensure actions are properly audited

under the agent's focused identity. *(Impersonation requires

roles/iam.serviceAccountTokenCreator)*.

For more detailed strategies and authentication types (such as Workload Identity

Federation), see

Authorizing the gcloud CLI.

Core Principles

1. Explicit Command Validation (Mandatory)

Your internal knowledge of gcloud may be stale or prone to hallucination

(e.g., hallucinating commands, flags, flag values, or positional argument

syntax). You are FORBIDDEN from executing commands until you have validated

the exact syntax at the leaf level.

intend to run (e.g., gcloud help compute instances create).

syntax are valid for that specific leaf command before attempting execution.

Validation is not transitive from parent groups.

2. Data Reduction Strategies

To save context window space and reduce latency, always minimize the volume of

data returned by gcloud.

specific fields needed for your task. To understand the advanced projection

and formatting syntax, refer to gcloud topic projections and `gcloud topic

formats`.

: for pattern matching and never quote the right side of the colon. Treat

the entire filter flag as a singular string without quoting or escaping

characters. To study the filter expression syntax, refer to `gcloud topic

filters`.

context window with redundant data. To prevent this, discover a resource's

schema before executing queries. If you are unsure of the JSON key path for

projecting fields (--format) or filtering (--filter), run the targeted

resource's list command (if supported) with a single-item limit:

```bash

gcloud <GROUP> <RESOURCE> list --limit=1 --format=json

```

Examine this single instance's JSON structure to safely identify the correct

schema keys before requesting full or filtered datasets.

3. Execution Constraints

chaining or sequencing.

(|), or redirection (>, >>, <). This is to increase command safety

and ensure commands are more easily understandable and reviewable by users.

a TTY (e.g., gcloud interactive). You must enforce non-interactive mode by

appending --quiet (or -q) to your commands. This ensures that defaults

are used or errors are raised if input is required.

4. Project and Location Scoping (Critical)

To ensure commands are deterministic, non-interactive, and target the correct

environment, you must explicitly manage project and location scoping.

Always append --project=<PROJECT_ID> to all resource-manipulating and

querying commands (unless running pure local config commands). This avoids

accidental execution against the wrong project.

zonal. If you omit the location flag (e.g., --region, --zone, or

--location), gcloud will trigger an interactive prompt to select a

zone/region. This violates the No Interactivity rule. Always provide

explicit location flags if the command requires them.

location for a service, run discovery commands first (remembering to limit

results if there are many):

unified locations list command:

list, gcloud secrets locations list`.

Safety & Guardrails

[!CAUTION] **Destructive actions (delete, update, remove) MUST be explicitly

authorized by the user.** Never invoke them autonomously unless explicitly

instructed to do so in the context of a safe, pre-approved workflow.

Prohibited Operations (Denylist)

You are strictly prohibited from executing the following commands

autonomously. These require explicit human-in-the-loop authorization:

privilege escalation, administrative lockout, service disruption, or

unauthorized data exposure.

unexpected resource provisioning or billing charges, do not proactively try

to enable APIs. User approval is required to enable any API.

(e.g., project deletion) or data wiping.

costs.

posture for all users.

execution can destroy managed resources.

Execution Guidelines

equivalent) first if it exists, before executing the actual command, to

preview changes.

flag is highly recommended for long-running operations to avoid blocking the

agentic flow. Note that not every command has an --async flag. For

commands that return an operation ID (whether via --async or by default),

you are responsible for polling for completion if the operation status is

needed for the next step.

Structured Workflows

Discovery Workflow

When asked to perform a task on a service you are not familiar with:

  1. You MUST invoke help on a command (e.g., gcloud help <COMMAND>) before

invoking it.

  1. If you do not know the exact command, traverse the command tree by invoking

help on a command group (e.g., gcloud help compute) to discover available

subcommands and groups.

  1. Schema Discovery: If you need to filter or project fields from a list

command, but do not know the exact JSON keys, first run `gcloud <GROUP>

<RESOURCE> list --limit=1 --format=json` to safely discover the schema.

Never run a raw list command without scoping constraints (like

--limit=1), as unconstrained results will pollute and exhaust your context

window.

  1. Execute with data reduction flags.

Quick Reference / Cheat Sheet

Task | Command Template

------------------ | ----------------------------------------------------------

Discover Schema | gcloud <GROUP> <RESOURCE> list --limit=1 --format=json

Filtered List | gcloud <GROUP> <RESOURCE> list --filter="status:RUNNING"

Specific Columns | gcloud <GROUP> <RESOURCE> list --format="json(name, id)"

Learn Filters | gcloud topic filters

Learn Formats | gcloud topic formats

Learn Projections | gcloud topic projections

Asynchronous Op | gcloud <COMMAND> --async

Check Operation | gcloud operations describe <OPERATION_ID>

Common commands | gcloud cheat-sheet

List Regions (GCE) | gcloud compute regions list --project=<PROJECT_ID>

List Zones (GCE) | gcloud compute zones list --project=<PROJECT_ID>

List Locations | gcloud <GROUP> locations list --project=<PROJECT_ID>

Refer to the

gcloud CLI Scripting Guide

for guidance on using the gcloud CLI in automation.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.