# GKE Agent Sandbox

Prepare the GKE cluster, namespace, and service account that let Sandcovery run Agent Sandbox in your own Google Cloud project.

Sandcovery creates each sandbox as an Agent Sandbox `Sandbox` in one namespace of your GKE cluster, through the cluster's DNS-based control plane endpoint and a service account key you add as the credential. The Agent Sandbox controller runs the sandbox's Pod in GKE Sandbox's gVisor runtime with the official Node.js 26 slim image, pinned by digest and pulled from Google's Docker Hub mirror, as user 1000 with every Linux capability dropped and no Kubernetes service account token. Commands, file reads, file writes, and listings run through the Kubernetes exec API over WebSocket, with each command's script and environment sent on its stdin, never in the request URL.

## What runs

| Option | Support |
| --- | --- |
| Size | `1x2`, `2x4`, `4x8`, and `8x16` |
| Disk | 10 MiB to 10 GiB of ephemeral storage |
| Egress | `allow_all`, within your cluster's own network policies |
| Environment variables | Yes |
| Lifetime | Until the sandbox's TTL |
| Pause and resume | No |
| Region | Your cluster's location |

Snapshots, port previews, custom images, idle timeouts, egress limits, region choice, and GPUs are not available on this provider. A create that asks for one routes to another provider.

Sandcovery waits up to 50 seconds for a new Sandbox to report Ready, and deletes it and tries the next provider when it does not, or at once when the Sandbox reports that its Pod failed, broke a resource quota, or is invalid. On an Autopilot cluster, a Pod that needs a new node can take several minutes to start, as Google's [install guide](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/how-install-agent-sandbox) notes, so a create can fail as a timeout until a node with room exists.

## Prepare the cluster

Use an Autopilot cluster, or a Standard cluster with a GKE Sandbox node pool, whose control plane has its DNS-based endpoint, as Google's [network isolation guide](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/latest/network-isolation) shows:

```sh
gcloud container clusters create-auto <cluster> --location=<location> \
  --enable-dns-access
```

Install Agent Sandbox as the [install guide](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/how-install-agent-sandbox) shows. Sandcovery's Pods meet the recommended security policy of that guide. Then create a namespace that holds only Sandcovery's sandboxes:

```sh
kubectl create namespace sandcovery
```

## Create the service account and its access

Create a service account for Sandcovery whose only Google Cloud permission is `container.clusters.connect`, which reaches the DNS-based endpoint, and a JSON key for it:

```sh
gcloud iam roles create sandcoveryGkeConnect --project=<project> \
  --title="Sandcovery GKE Connect" \
  --permissions=container.clusters.connect
gcloud iam service-accounts create sandcovery --project=<project> \
  --display-name="Sandcovery"
gcloud projects add-iam-policy-binding <project> \
  --member="serviceAccount:sandcovery@<project>.iam.gserviceaccount.com" \
  --role="projects/<project>/roles/sandcoveryGkeConnect"
gcloud iam service-accounts keys create sandcovery-key.json \
  --iam-account=sandcovery@<project>.iam.gserviceaccount.com
```

Then apply a Role that lets it create, read, change, and delete Sandboxes and run commands in their Pods in that namespace alone:

```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: sandcovery
  namespace: sandcovery
rules:
  - apiGroups: [agents.x-k8s.io]
    resources: [sandboxes]
    verbs: [create, get, patch, delete]
  - apiGroups: ['']
    resources: [pods/exec]
    verbs: [create, get]
```

Bind that Role to the service account's email as a `User`, as Google's [RBAC guide](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control) shows:

```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: sandcovery
  namespace: sandcovery
subjects:
  - kind: User
    name: sandcovery@<project>.iam.gserviceaccount.com
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: sandcovery
```

If your organization blocks service account key creation, override that policy on this project as [Google Agent Platform Code Execution](/docs/providers/google-agent-platform#when-your-organization-blocks-key-creation) shows.

## Add the credential

In **Provider Credentials** in the [dashboard](/app/credentials), add these three fields for GKE Agent Sandbox:

- Service account JSON key: the whole contents of `sandcovery-key.json`
- DNS-based control plane endpoint: the host under `gke.goog` that `gcloud container clusters describe <cluster> --location=<location> --format="value(controlPlaneEndpointsConfig.dnsEndpointConfig.endpoint)"` prints
- Namespace: `sandcovery`

Sandcovery signs a token request with the key at Google's token endpoint and sends the cluster only the one-hour access token Google returns. Deleting the key in Google Cloud revokes it, and an access token it already bought expires within the hour.

## Costs

Google bills your cluster and each sandbox's Pod to your Google Cloud billing account. Sandcovery's estimates and spend limits count a sandbox at GKE Autopilot's on-demand [list price](/providers/gke) for a general-purpose Pod in `us-central1`, and leave out ephemeral storage and the cluster management fee.
