This document explains how to install the open source
[Agent Sandbox](https://github.com/kubernetes-sigs/agent-sandbox)
controller on a Google Kubernetes Engine (GKE) cluster to run isolated agent
workloads in dedicated Kubernetes Pods. You also learn how to create a
Sandbox resource that runs untrusted code in the gVisor runtime. For most
agent workloads, use [Agent Substrate on GKE](https://docs.cloud.google.com/kubernetes-engine/ai-ml/about-agent-substrate.md.txt)
instead, because it can run more agents on the same nodes. Use
Agent Sandbox on GKE when each agent needs a dedicated
Pod, GPUs or TPUs, a full Kubernetes PodSpec, or a GKE
Autopilot cluster. To compare Agent Sandbox on
GKE with Agent Substrate on GKE and
choose an architecture for your AI agent workloads, see
[Plan an architecture for AI agent workloads on GKE](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/machine-learning/agent-workloads.md.txt).

For an overview of how Agent Sandbox on GKE isolates
untrusted AI-generated code, see
[About Agent Sandbox on GKE](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/machine-learning/agent-sandbox.md.txt).

## Costs

Agent Sandbox on GKE is open source software that you
can use at no extra charge.
[GKE pricing](https://cloud.google.com/kubernetes-engine/pricing)
applies to the resources that you create, including the compute resources that
the Agent Sandbox controller uses.

To avoid unnecessary charges, ensure that you disable GKE or
delete the project after you have completed this document.

## Before you begin

1. In the Google Cloud console, on the project selector page,
   select or create a Google Cloud project.

   **Roles required to select or create a project**
   - **Select a project**: Selecting a project doesn't require a specific IAM role---you can select any project that you've been granted a role on.
   - **Create a project** : To create a project, you need the Project Creator role (`roles/resourcemanager.projectCreator`), which contains the `resourcemanager.projects.create` permission. [Learn how to grant
     roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).

   > [!NOTE]
   > **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

   [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)
2.
   [Verify that billing is enabled for your Google Cloud project](https://docs.cloud.google.com/billing/docs/how-to/verify-billing-enabled.md.txt#confirm_billing_is_enabled_on_a_project).

3.


   Enable the Google Kubernetes Engine API, if it is not already enabled.


   **Roles required to enable APIs**


   To enable APIs, you need the `serviceusage.services.enable` permission. If you
   created the project, then you likely already have this permission through the
   Owner role (`roles/owner`). Otherwise, you can get this permission through the
   Service Usage Admin role (`roles/serviceusage.serviceUsageAdmin`).
   [Learn how to grant roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

   [Enable the API](https://console.cloud.google.com/apis/enableflow?apiid=container.googleapis.com)
4. In the Google Cloud console, activate Cloud Shell.

   [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)

## Define environment variables

To simplify the commands that you run in this document, you can set environment
variables in Cloud Shell. In Cloud Shell, define the following useful
environment variables by running the following commands:

```bash
export CLUSTER_NAME="agent-sandbox-cluster"
export LOCATION="us-central1"
export AGENT_SANDBOX_VERSION="v1.0.6"
export NODE_POOL_NAME="agent-sandbox-pool"
export MACHINE_TYPE="e2-standard-2"
```

Here's an explanation of these environment variables:

- `CLUSTER_NAME`: the name of your GKE cluster---for example, `agent-sandbox-cluster`.
- `LOCATION`: the Google Cloud region or zone where your GKE cluster is created. If you create an Autopilot cluster, set this to the region (for example, `us-central1`). Autopilot clusters are always regional. If you create a Standard cluster, set this to the zone (for example, `us-central1-a`). To reduce costs, this document creates a zonal cluster, which uses fewer nodes than a regional cluster.
- `AGENT_SANDBOX_VERSION`: the version of the open source Agent Sandbox controller to install. This document uses version 1.0.6. To see other versions, go to the [Agent Sandbox releases page](https://github.com/kubernetes-sigs/agent-sandbox/releases).
- `NODE_POOL_NAME`: the name of the node pool that will run your agent Pods---for example, `agent-sandbox-pool`. This variable is only required if you are creating a GKE Standard cluster.
- `MACHINE_TYPE`: the machine type of the nodes in your cluster's default node pool and in the gVisor node pool---for example, `e2-standard-2`. For details about different machine series and choosing between different options, see the [Machine families resource and comparison guide](https://docs.cloud.google.com/compute/docs/machine-resource.md.txt). This variable is only required if you are creating a GKE Standard cluster.

## Create a GKE cluster

Agent Sandbox on GKE isolates agent workloads by using
[GKE Sandbox](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/sandbox-pods.md.txt) with
[gVisor](https://gvisor.dev/docs/) or
[microVMs](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/sandbox-pods.md.txt#sandbox-technologies).
If you don't specify a GKE Sandbox runtime (gVisor or microVMs), your
Pods run without kernel isolation, so don't use them to run untrusted code.
This document uses gVisor. Autopilot clusters enable gVisor
automatically. In Standard clusters, you create a node pool that
has gVisor enabled. To use microVMs instead, see [Enable the microVM sandbox
type](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/sandbox-pods#enable-microvm). The
[recommended security policy](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/how-install-agent-sandbox.md.txt#apply-security-policy) allows only gVisor, so it
rejects Sandbox resources that use microVMs.

> [!IMPORTANT]
> **Best practice** :
>
> Use an Autopilot cluster for a fully managed Kubernetes experience.
> To choose the GKE mode of operation that's the best fit for your
> workloads, see
> [Choose a GKE mode of
> operation](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/choose-cluster-mode).

### Autopilot

To create an Autopilot cluster, make sure that the `LOCATION`
environment variable is set to a region, such as `us-central1`, and then
run the following command:

```bash
gcloud container clusters create-auto ${CLUSTER_NAME} \
    --location=${LOCATION}
```

### Standard

To create a Standard cluster, you create the cluster and then add
a node pool with gVisor enabled. To reduce costs, this document creates a
zonal cluster with a single node per pool.

> [!IMPORTANT]
> **Best practice** :
>
> Use a
> [regional cluster](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/regional-clusters.md.txt) for
> production workloads. Regional clusters replicate the control plane and
> nodes across multiple zones, which provides higher availability than zonal
> clusters.

1. Set the `LOCATION` environment variable to a zone, such as
   `us-central1-a`:

   ```bash
   export LOCATION="us-central1-a"
   ```
2. Create the cluster:

   ```bash
   gcloud container clusters create ${CLUSTER_NAME} \
       --location=${LOCATION} \
       --machine-type=${MACHINE_TYPE} \
       --num-nodes=1
   ```
3. Create a separate node pool with gVisor enabled:

   ```bash
   gcloud container node-pools create ${NODE_POOL_NAME} \
       --cluster=${CLUSTER_NAME} \
       --machine-type=${MACHINE_TYPE} \
       --location=${LOCATION} \
       --num-nodes=1 \
       --image-type=cos_containerd \
       --sandbox=type=gvisor
   ```

   To use microVMs instead of gVisor, create the node pool as described in
   [Enable the microVM sandbox
   type](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/sandbox-pods#enable-microvm). The
   rest of this document uses gVisor.

To use an existing Standard cluster instead, make sure that the cluster
includes a node pool that has gVisor enabled. If the cluster doesn't have such a
node pool, create one by running the preceding
`gcloud container node-pools create` command.

To enable the `kubectl` command-line tool to connect to the cluster, get
the cluster credentials:

```bash
gcloud container clusters get-credentials ${CLUSTER_NAME} \
    --location=${LOCATION}
```

## Install Agent Sandbox

To install Agent Sandbox, apply a release manifest from the
Agent Sandbox GitHub repository. The
`sandbox-with-extensions.yaml` manifest installs the
Agent Sandbox controller and the CustomResourceDefinitions for
the Sandbox resource and for the SandboxTemplate, SandboxClaim, and
SandboxWarmPool extension resources.

1. Apply the release manifest:

   ```bash
   kubectl apply -f https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${AGENT_SANDBOX_VERSION}/sandbox-with-extensions.yaml
   ```

   The manifest creates the `agent-sandbox-system` namespace and deploys the
   controller in that namespace.
2. Wait until the controller is ready:

   ```bash
   kubectl rollout status deployment/agent-sandbox-controller \
       --namespace=agent-sandbox-system \
       --timeout=120s
   ```

   > [!NOTE]
   > **Note:** In an Autopilot cluster, the controller can take several minutes to become ready because GKE might need to create a node for it. If the command times out before the controller is ready, run the command again.

You can also install Agent Sandbox by using Helm. For
instructions, see the
[Agent Sandbox Helm chart README](https://github.com/kubernetes-sigs/agent-sandbox/blob/v1.0.6/helm/README.md).

## Verify the installation

1. Verify that the Agent Sandbox CustomResourceDefinitions are
   installed:

   ```bash
   kubectl get crd \
       sandboxes.agents.x-k8s.io \
       sandboxtemplates.extensions.agents.x-k8s.io \
       sandboxclaims.extensions.agents.x-k8s.io \
       sandboxwarmpools.extensions.agents.x-k8s.io
   ```

   The output lists the four CustomResourceDefinitions.
2. Verify that the controller is running:

   ```bash
   kubectl get deployment agent-sandbox-controller \
       --namespace=agent-sandbox-system
   ```

   When the controller is running, the `READY` column shows `1/1`.

## Apply the recommended security policy

By default, Agent Sandbox on GKE doesn't restrict the
configuration of the Pods that run your agents. To help enforce isolation
settings for your agent Pods, apply the recommended `secure-sandbox-policy`
[ValidatingAdmissionPolicy](https://kubernetes.io/docs/reference/access-authn-authz/validating-admission-policy/)
from the Agent Sandbox GitHub repository. This policy rejects any
Sandbox resource that doesn't meet the [Agent Sandbox on
GKE deployment requirements](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/how-install-agent-sandbox#deployment-requirements).

1. Apply the policy:

   ```bash
   kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/agent-sandbox/${AGENT_SANDBOX_VERSION}/examples/policy/vap/secure-sandbox-policy.yaml
   ```
2. Apply the policy binding. The binding enforces the policy in all namespaces
   except system namespaces, such as `kube-system`:

   ```bash
   kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/agent-sandbox/${AGENT_SANDBOX_VERSION}/examples/policy/vap/secure-sandbox-binding.yaml
   ```

The policy validates Sandbox resources. When you create a SandboxWarmPool
resource or a SandboxClaim resource, the controller creates Sandbox resources
from a SandboxTemplate resource. If the template doesn't meet the requirements,
the policy rejects the Sandbox resource, and the error appears in the controller
logs. To view the logs, run the following command:

```bash
kubectl logs deployment/agent-sandbox-controller \
    --namespace=agent-sandbox-system
```

You own this policy, and you can modify it to fit your workloads. For more
information, see
[Sandbox security policies](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/agent-sandbox.md.txt#sandbox-security-policies).

## Agent Sandbox on GKE deployment requirements

If you apply the [recommended security policy](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/how-install-agent-sandbox.md.txt#apply-security-policy), your
workload manifests, such as a Sandbox or SandboxTemplate resource, must include
specific security and configuration settings. If a Sandbox resource doesn't meet
these requirements, the admission controller rejects it. The container
requirements apply to all containers in the Pod, including init containers and
ephemeral containers.

### Required configuration

Your deployment manifest must include the following settings:

- `runtimeClassName: gvisor`: runs the Pod in the gVisor runtime of GKE Sandbox. The policy rejects Sandbox resources that use any other runtime, including microVMs.
- `automountServiceAccountToken: false`: prevents the Pod from automatically mounting the default service account token.
- `securityContext.runAsNonRoot: true`: ensures the container does not run as the root user.
- `securityContext.capabilities.drop: ["ALL"]`: drops all Linux capabilities from the container.
- `resources.limits`: you must specify CPU and memory limits to prevent potential denial-of-service (DoS) scenarios.
- `nodeSelector`: must target `sandbox.gke.io/runtime: gvisor`.
- `tolerations`: must include a toleration for the `sandbox.gke.io/runtime=gvisor:NoSchedule` taint.

### Prohibited configuration

Your deployment manifest must **not** include any of the following:

- `hostNetwork: true`, `hostPID: true`, or `hostIPC: true`.
- `privileged: true` in container security contexts.
- `procMount: Unmasked` in container security contexts.
- `HostPath` volumes.
- Added capabilities (`capabilities.add`).
- `hostPort` settings.
- Custom sysctls.
- Projected volumes for service account tokens or certificates.

## Deploy the Sandbox Router (optional)

The Sandbox Router is an HTTP proxy that routes requests from clients, such as
the [Agent Sandbox Python client](https://pypi.org/project/k8s-agent-sandbox/),
to the Pods that run your agents. If you plan to use the Python client, for
example as described in [Isolate AI code execution with
Agent Sandbox on GKE](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/agent-sandbox),
deploy the router.

You deploy the router in the `agent-sandbox-system` namespace. By default, the
network policy that Agent Sandbox on GKE creates for
each SandboxTemplate resource allows incoming traffic to agent Pods only from
the router Pods in this namespace.

1. Create the router's service account and the RBAC permissions that let the
   router look up agent Pods:

   ```bash
   kubectl apply \
       -f https://raw.githubusercontent.com/kubernetes-sigs/agent-sandbox/${AGENT_SANDBOX_VERSION}/sandbox-router/deploy/serviceaccount.yaml \
       -f https://raw.githubusercontent.com/kubernetes-sigs/agent-sandbox/${AGENT_SANDBOX_VERSION}/sandbox-router/deploy/rbac.yaml
   ```
2. Deploy the router. The following command sets the router image to the same
   version as the controller:

   ```bash
   curl -sSL https://raw.githubusercontent.com/kubernetes-sigs/agent-sandbox/${AGENT_SANDBOX_VERSION}/sandbox-router/deploy/deployment.yaml \
       | sed "s|sandbox-router-go:latest|sandbox-router-go:${AGENT_SANDBOX_VERSION}|" \
       | kubectl apply -f -
   ```
3. Create the router's Service:

   ```bash
   kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/agent-sandbox/${AGENT_SANDBOX_VERSION}/sandbox-router/deploy/service.yaml
   ```
4. Wait until the router is ready:

   ```bash
   kubectl rollout status deployment/sandbox-router \
       --namespace=agent-sandbox-system \
       --timeout=120s
   ```

This router configuration is for development and testing. For
production settings, such as TLS, replica counts, and network policies for the
router, see the
[Sandbox Router deployment README](https://github.com/kubernetes-sigs/agent-sandbox/blob/v1.0.6/sandbox-router/deploy/README.md).

## Export controller metrics (optional)

The Agent Sandbox controller exports Prometheus metrics at the
`/metrics` path on the `metrics` port (port 8080). To collect these metrics
by using Google Cloud Managed Service for Prometheus and to query them in Cloud Monitoring,
apply a PodMonitoring custom resource.

GKE enables managed collection by default on Autopilot
clusters that run GKE version 1.25 or later and on
Standard clusters that run GKE version 1.27 or later.
If your cluster doesn't have managed collection enabled, see
[Enable managed collection manually](https://docs.cloud.google.com/stackdriver/docs/managed-prometheus/setup-managed.md.txt#enable-mgdcoll-gke-manual).

Because Prometheus counters and histograms don't record activity that occurred
before collection started, apply the PodMonitoring resource after you
install the controller so that Cloud Monitoring captures early cluster and
Sandbox resource events.

1. In Cloud Shell, create a file named `agent-sandbox-monitoring.yaml` with
   the following content:

   ```yaml
   apiVersion: monitoring.googleapis.com/v1
   kind: PodMonitoring
   metadata:
     name: agent-sandbox-controller
     namespace: agent-sandbox-system
   spec:
     selector:
       matchLabels:
         app: agent-sandbox-controller
     endpoints:
     - port: metrics
       path: /metrics
       interval: 30s
   ```

   > [!NOTE]
   > **Note:** If you installed Agent Sandbox by using Helm, replace `app: agent-sandbox-controller` with `app.kubernetes.io/name: agent-sandbox` in the `spec.selector.matchLabels` field. If you installed the Helm chart in a custom namespace, also set the `metadata.namespace` field to that namespace (a PodMonitoring resource must be in the same namespace as the controller Pods).

2. Apply the manifest:

   ```bash
   kubectl apply -f agent-sandbox-monitoring.yaml
   ```

After you apply the PodMonitoring resource, Google Cloud Managed Service for Prometheus
scrapes the controller metrics every 30 seconds. You can query these metrics
with PromQL in Cloud Monitoring by using
[Metrics Explorer](https://docs.cloud.google.com/monitoring/charts/metrics-explorer.md.txt).

In Cloud Monitoring, Google Cloud Managed Service for Prometheus reserves the
`namespace` label for the namespace of the scraped controller Pod
(`agent-sandbox-system`). For metrics that define their own `namespace` label,
Google Cloud Managed Service for Prometheus renames the metric label to
`exported_namespace`. To filter or group metrics by the Sandbox resource's
namespace, use the `exported_namespace` label. For more information, see
[Reserved labels](https://docs.cloud.google.com/stackdriver/docs/managed-prometheus/setup-managed.md.txt#reserved-labels).

For example, you can query the following metrics:

- `agent_sandbox_build_info`: build information about the controller,
  such as the Git commit and version.

- `agent_sandboxes`: the point-in-time number of Sandbox resources in the
  cluster. This metric has labels for readiness, expiration, launch type,
  owner, creator, template, and the Sandbox resource's namespace
  (`exported_namespace`). For example, the following PromQL query groups
  Sandbox resources by namespace and readiness:

  ```promql
  sum by (exported_namespace, ready_condition) (agent_sandboxes)
  ```
- `agent_sandbox_claim_controller_startup_latency_ms`: a histogram that
  measures the latency in milliseconds from when the controller first
  observes a SandboxClaim resource until the claim reaches the `Ready` status.
  Because this metric is a Prometheus histogram, querying the base metric
  name returns no data directly. You must query its `_bucket`, `_sum`, or
  `_count` series. For example, the following PromQL query calculates the
  95th percentile startup latency over a five-minute rate window:

  ```promql
  histogram_quantile(
    0.95,
    sum by (le) (
      rate(agent_sandbox_claim_controller_startup_latency_ms_bucket[5m])
    )
  )
  ```

> [!NOTE]
> **Note:** The controller exports the `agent_sandboxes` and `agent_sandbox_claim_controller_startup_latency_ms` metrics only after you create Sandbox and SandboxClaim resources in [Deploy a sandboxed environment](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/how-install-agent-sandbox.md.txt#deploy-a-sandboxed-environment).

For more information about exported metrics and the optional components that
they depend on, see the
[Controller Metrics Reference](https://agent-sandbox.sigs.k8s.io/docs/metrics/).

## Deploy a sandboxed environment

To deploy a sandboxed environment, define a SandboxTemplate resource and keep
pre-warmed Sandbox resources ready by using a SandboxWarmPool resource. You can
then request a Sandbox resource from this warm pool by using a SandboxClaim
resource. Alternatively, you can create a Sandbox resource directly, but this
approach doesn't support warm pools.

SandboxTemplate, SandboxWarmPool, SandboxClaim, and Sandbox are
[Kubernetes custom resources](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/).

### Recommended: Create SandboxTemplate and SandboxWarmPool resources

The SandboxTemplate resource acts as a reusable blueprint. The SandboxWarmPool
resource maintains a specified number of pre-warmed Sandbox resources with
running Pods that are ready to be claimed. This warm pool reduces startup
latency.

To deploy a sandboxed environment by creating SandboxTemplate and
SandboxWarmPool resources, complete the following steps:

1. In Cloud Shell, create a file named `sandbox-template.yaml` with the
   following content:

   ```yaml
   apiVersion: extensions.agents.x-k8s.io/v1beta1
   kind: SandboxTemplate
   metadata:
     name: python-runtime-template
     namespace: default
   spec:
     podTemplate:
       metadata:
         labels:
           sandbox-type: python-runtime
       spec:
         runtimeClassName: gvisor # Required
         automountServiceAccountToken: false # Required
         securityContext:
           runAsNonRoot: true # Required
         nodeSelector:
           sandbox.gke.io/runtime: gvisor # Required
         tolerations:
         - key: "sandbox.gke.io/runtime"
           value: "gvisor"
           effect: "NoSchedule" # Required
         containers:
         - name: runtime
           image: registry.k8s.io/agent-sandbox/python-runtime-sandbox:v0.1.0
           ports:
           - containerPort: 8888
           resources:
             requests:
               cpu: "250m"
               memory: "512Mi"
             limits:
               cpu: "500m"
               memory: "1Gi" # Required
           securityContext:
             capabilities:
               drop: ["ALL"] # Required
         restartPolicy: OnFailure
   ```
2. Apply the SandboxTemplate manifest:

   ```bash
   kubectl apply -f sandbox-template.yaml
   ```
3. Create a file named `sandbox-warmpool.yaml` with the following content:

   ```yaml
   apiVersion: extensions.agents.x-k8s.io/v1beta1
   kind: SandboxWarmPool
   metadata:
     name: python-runtime-warmpool
     namespace: default
     labels:
       app: python-runtime-warmpool
   spec:
     replicas: 2
     sandboxTemplateRef:
       # This must match the name of the SandboxTemplate.
       name: python-runtime-template
   ```
4. Apply the SandboxWarmPool manifest:

   ```bash
   kubectl apply -f sandbox-warmpool.yaml
   ```
5. Wait until the warm pool's Sandbox resources and their Pods are ready:

   ```bash
   kubectl wait sandboxwarmpool python-runtime-warmpool \
       --for=jsonpath='{.status.readyReplicas}'=2 \
       --timeout=600s
   ```

   If you create a SandboxClaim resource before the pool's Sandbox resources
   and their Pods are ready, the controller creates a new Sandbox resource for
   the claim instead of assigning one from the pool. In an Autopilot
   cluster, the Pods can take several minutes to become ready because
   GKE might need to create nodes for them.

### Create a SandboxClaim resource

The SandboxClaim resource requests a Sandbox resource from the warm pool.
Because you created a warm pool, the controller assigns a ready Sandbox
resource (and its running Pod) from the pool to the claim instead of creating a
new one.

To request a Sandbox resource from the warm pool by creating a SandboxClaim
resource, complete the following steps:

1. Create a file named `sandbox-claim.yaml` with the following content:

   ```yaml
   apiVersion: extensions.agents.x-k8s.io/v1beta1
   kind: SandboxClaim
   metadata:
     name: sandbox-claim
     namespace: default
   spec:
     warmPoolRef:
       # This must match the name of the SandboxWarmPool.
       name: python-runtime-warmpool
   ```
2. Apply the SandboxClaim manifest:

   ```bash
   kubectl apply -f sandbox-claim.yaml
   ```
3. Verify that the Sandbox resource, claim, and warm pool are ready:

   ```bash
   kubectl get sandboxwarmpool,sandboxclaim,sandbox,pod
   ```

### Alternative: Create a Sandbox resource directly

If you don't need the fast startup times provided by warm pools, you can deploy
a Sandbox resource directly without using templates.

To deploy a sandboxed environment by creating a Sandbox resource directly,
complete the following steps:

1. Create a file named `sandbox.yaml` with the following content:

   ```yaml
   apiVersion: agents.x-k8s.io/v1beta1
   kind: Sandbox
   metadata:
     name: sandbox-example-2
   spec:
     podTemplate:
       metadata:
         labels:
           sandbox: sandbox-example
       spec:
         runtimeClassName: gvisor
         restartPolicy: OnFailure
         automountServiceAccountToken: false # Required
         securityContext:
           runAsNonRoot: true # Required
           runAsUser: 1000 # Required if image defaults to root (for example, busybox)
         nodeSelector:
           sandbox.gke.io/runtime: gvisor
         tolerations:
         - key: "sandbox.gke.io/runtime"
           value: "gvisor"
           effect: "NoSchedule" # Required
         containers:
         - name: my-container
           image: busybox
           command: ["/bin/sh", "-c"]
           args: ["sleep 3600000; echo 'Container finished successfully'; exit 0"]
           securityContext:
             capabilities:
               drop: ["ALL"] # Required
             allowPrivilegeEscalation: false
           resources:
             limits:
               cpu: "100m"
               memory: "128Mi" # Required
   ```
2. Apply the Sandbox manifest:

   ```bash
   kubectl apply -f sandbox.yaml
   ```
3. Verify that the Sandbox resource is running:

   ```bash
   kubectl get sandbox
   ```

## Upgrade Agent Sandbox

To upgrade Agent Sandbox, apply the release manifest for the new
version:

```bash
export AGENT_SANDBOX_VERSION="NEW_VERSION"
kubectl apply -f https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${AGENT_SANDBOX_VERSION}/sandbox-with-extensions.yaml
```

Replace `NEW_VERSION` with the version that you want to install, such as a
version listed on the
[Agent Sandbox releases page](https://github.com/kubernetes-sigs/agent-sandbox/releases).

Before you upgrade, review the release notes for the new version. If your
cluster runs a version of Agent Sandbox earlier than 1.0.0, you
must migrate your resources to the `v1beta1` API before you upgrade, because
version 1.0.0 removed the `v1alpha1` API. For instructions, see the
[API migration guide](https://github.com/kubernetes-sigs/agent-sandbox/blob/v1.0.6/docs/api-migration-guide.md).

If you deployed the Sandbox Router or applied the recommended security policy,
repeat those steps for the new version.

## Uninstall Agent Sandbox

> [!CAUTION]
> **Caution:** Uninstalling Agent Sandbox deletes the Agent Sandbox CustomResourceDefinitions, which also deletes all Sandbox, SandboxTemplate, SandboxClaim, and SandboxWarmPool resources in all namespaces.

1. Check for Agent Sandbox resources that are still in use:

   ```bash
   kubectl get sandboxes,sandboxclaims,sandboxwarmpools,sandboxtemplates \
       --all-namespaces
   ```
2. If you applied the recommended security policy, delete the policy binding
   and the policy:

   ```bash
   kubectl delete validatingadmissionpolicybinding secure-sandbox-binding
   kubectl delete validatingadmissionpolicy secure-sandbox-policy
   ```
3. If you deployed the Sandbox Router, delete its cluster-wide RBAC resources:

   ```bash
   kubectl delete -f https://raw.githubusercontent.com/kubernetes-sigs/agent-sandbox/${AGENT_SANDBOX_VERSION}/sandbox-router/deploy/rbac.yaml
   ```

   The router's other resources are in the `agent-sandbox-system` namespace,
   which the next step deletes.
4. To delete the Agent Sandbox controller, its namespace, and
   its CustomResourceDefinitions, delete the release manifest for the version
   that you installed:

   ```bash
   kubectl delete -f https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${AGENT_SANDBOX_VERSION}/sandbox-with-extensions.yaml
   ```

## Clean up resources

To avoid incurring charges to your Google Cloud account, delete the
GKE cluster that you created.

```bash
gcloud container clusters delete ${CLUSTER_NAME} \
    --location=${LOCATION} \
    --quiet
```

If you created an Autopilot cluster, the location is the region (for
example, `us-central1`). If you created a Standard cluster, the
location is the zone (for example, `us-central1-a`).

## What's next

- Learn how to [save and restore Agent Sandbox on GKE environments with Pod snapshots](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/agent-sandbox-pod-snapshots.md.txt).
- Learn how [GKE Sandbox](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/sandbox-pods.md.txt) isolates workloads by using gVisor or microVMs.
- Learn more about [GKE security](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/security-overview.md.txt).
- Explore the [Agent Sandbox open-source project](https://github.com/kubernetes-sigs/agent-sandbox) on GitHub.
- Learn how to use open source [Kata Containers with Agent Sandbox on GKE](https://github.com/kubernetes-sigs/agent-sandbox/tree/v1.0.6/examples/kata-gke-sandbox). Kata Containers isn't a Google Cloud product. If you install and use this software, then you're responsible for management and troubleshooting. Google's support and SLAs don't apply to Kata Containers.