gcloud Skill: Constraining GCP CLI Operations for AI Agents

Introduction

Having an Agent directly assemble gcloud subcommands and guess flags often leads to syntax errors or accidental resource deletions. Even if the commands are correct, unbounded list output can consume the entire context. A common practice is to have humans review every command, or to switch to client libraries and REST APIs. However, in operations and troubleshooting scenarios, the CLI remains the most direct entry point.

Below we introduce the gcloud Skill (metadata version 1.0.0, category CloudInfrastructureAndServices) maintained by Google in the google/skills repository. Designed for AI Agents, it provides syntax validation workflows, execution guardrails, and data reduction rules when planning, generating, describing, or executing gcloud-related tasks. The official description explicitly states: do not use this Skill when writing Google Cloud client library code or raw REST/gRPC requests.

What This Is

gcloud is an Agent Skill document (SKILL.md), not a Cloud SDK installation package. It specifies mandatory steps and prohibited actions for Agents interacting with the Google Cloud SDK (gcloud CLI). Its goals are to reduce command hallucination, prevent destructive automatic execution, and control the volume of returned data.

Maintainer and source path: https://github.com/google/skills/tree/main/skills/cloud/gcloud.

Core Features

Leaf-Level Syntax Validation (Mandatory Prerequisite)

The Skill mandates that any prior knowledge Agents have about gcloud commands, flags, values, and positional arguments be treated as outdated and prone to hallucination. Before proposing arguments, executing commands, or writing step-by-step plans, Agents must validate the leaf subcommand first:

gcloud help compute instances create

Key points:

  1. Parent-level help (e.g., gcloud help compute) cannot replace leaf-command validation.
  2. In any plan, Step 1 must be gcloud help <leaf_command> before discussing flags or execution.
  3. Prohibited to use web searches or external documentation for CLI syntax; gcloud help <leaf_command> is the sole authoritative source for syntax.
  4. Flags provided by the user (including --project=<project_id>) must be preserved in intermediate steps.

When generating plans, follow the officially specified four-step structure:

  • Step 1: Run gcloud help <leaf_command> for syntax validation
  • Step 2: Check required/optional flags, and confirm whether --dry-run or --validate-only are supported
  • Step 3: If dry-run is supported, first present an invocation with --dry-run or --validate-only
  • Step 4: Propose the formal command; if it falls under the “prohibited autonomous execution” list, state the prohibition and explicitly request user authorization

Two Execution Modes

Agents can operate on GCP resources in two ways:

  • Direct CLI: Execute gcloud in a local or automated shell (installation, authentication, and configuration are covered in the Skill’s references/cli-usage.md).
  • MCP: Use the structured tool run_gcloud_command from the Cloud CLI remote MCP server (see references/mcp-usage.md).

Data Reduction (Mandatory)

Any list command must include at least one reduction mechanism: --limit, --filter, or --format.

  • Projection: --format="json(key1, key2, ...)"; advanced syntax can be found via gcloud topic projections, gcloud topic formats.
  • Result limit: --limit=N.
  • Filtering: --filter narrows results server-side; prefer using : for pattern matching, and omit quotes on the right side of the colon.
  • Schema discovery: When unsure about JSON field paths, first fetch a single sample:
gcloud <GROUP> <RESOURCE> list --limit=1 --format=json

Then construct --format or --filter based on the structure to avoid unbounded lists flooding the context.

Execution Constraints

  • Execute only one gcloud command at a time; do not chain commands.
  • Do not use command substitution, pipes, or redirections, to facilitate human review.
  • All executable commands should include --quiet / -q to avoid hanging on confirmation prompts in non-TTY environments.
  • Bare list (without --limit, --filter, --format) is prohibited.

Project and Location Scoping

  • Resource query and modification commands must explicitly include --project=<PROJECT_ID> instead of relying on the current default configuration.
  • Commands that require region/zone/location must explicitly pass these parameters, otherwise they may trigger interactive prompts that conflict with non-interactive runs.
  • When locations are unknown, perform discovery first (and apply data reduction), e.g.:
gcloud compute regions list --project=<PROJECT_ID>
gcloud compute zones list --project=<PROJECT_ID>
gcloud locations list --project=<PROJECT_ID>

Safety Guardrails and Prohibited Autonomous Execution List

Destructive operations (delete, update, remove, etc.) must receive explicit user authorization. The Skill lists categories that must not be executed autonomously, including but not limited to:

  • Changes to IAM policies, roles, or bindings
  • Enabling APIs (requires user approval to avoid unexpected billing)
  • gcloud * delete, gcloud billing *, gcloud organizations *, gcloud kms *
  • gcloud infra-manager deployments apply

If --dry-run or --validate-only are supported according to the help output, they must be used first to preview changes. For long-running operations, consider --async when supported, and poll operation status as needed.

Installation and Activation

The gcloud Skill is distributed as part of the google/skills repository. The official installation command is:

npx skills add google/skills

Follow the prompts to select the specific Skill (you may choose only gcloud), the target Agent, and the installation scope (project or global). If your environment lacks npx, install Node.js (which includes npm/npx) first. To update an already installed Skill:

npx skills update

The repository README does not separately list steps for Cursor, Codex CLI, or Claude Code; installation is uniformly handled via the skills.sh workflow. The Skill itself consists of Markdown rules and reference documents. The Agent side must have the Google Cloud SDK installed and authenticated. CLI paths and MCP configuration details are located in the Skill directory under references/.

Typical Usage

Discovery Workflow When Services Are Unfamiliar

  1. Run gcloud help <leaf_command> for the target leaf command.
  2. If the command name is unknown, navigate the command tree via gcloud help or gcloud help <group>.
  3. Use --limit=1 --format=json for schema discovery.
  4. For subsequent list/query operations, always include data reduction flags.

Plan Template Example (Logical Order)

Take creating a Compute Engine instance as an example. The Agent should first validate syntax, then discuss parameters and dry-run (specific flags depend on the help output):

gcloud help compute instances create

After confirming dry-run support, propose a preview command with --dry-run plus --quiet, --project, region/zone, or other user-specified parameters. Only then proceed to Step 4’s formal proposal or execution (provided the command is not on the denylist).

Quick Reference (from the Official Skill)

Task Command Template
Schema discovery gcloud <GROUP> <RESOURCE> list --limit=1 --format=json
Filtering lists gcloud <GROUP> <RESOURCE> list --filter="status:RUNNING"
Specifying columns gcloud <GROUP> <RESOURCE> list --format="json(name, id)"
Learning filter syntax gcloud topic filters

For automation scripts, the Skill points to the gcloud CLI Scripting Guide.

Suitable Scenarios and Caveats

Suitable for: Agent-driven planning or execution of GCP operations, troubleshooting, and resource queries; teams requiring a unified “help first, then dry-run, then execute” workflow; environments using MCP run_gcloud_command for structured invocation.

Not suitable for: Writing Cloud client libraries or directly composing REST/gRPC requests (use the corresponding development Skill or documentation instead).

Note: The strict rules (single command, no pipes, prohibition on supplementing syntax via search) are intended for reviewability and safety. Operations on the denylist still require explicit authorization even if the user’s intent is clear. List and discovery commands must include --project and data reduction; otherwise they may operate on the wrong project or overwhelm the context.

Conclusion

The gcloud Skill codifies “leaf help validation, four-step planning, data reduction, explicit project/location scoping, denylist enforcement, and dry-run” into a unified set of specifications that Agents can follow. It serves as the official, first-hand source of constraints for safely invoking the GCP CLI with Agents. Source code and complete rules are available at: https://github.com/google/skills/tree/main/skills/cloud/gcloud.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye