# Google Agent Platform Code Execution

Create the Agent Platform instance and the service account key that let Sandcovery run Code Execution sandboxes in your own Google Cloud project.

Sandcovery runs Google's Code Execution sandboxes under an Agent Platform instance in your Google Cloud project, through a service account key you add as the credential. Sandcovery makes Python sandboxes, which have no network access, and runs each command, file read, file write, and listing as a short Python program.

## What runs

| Option           | Support                                      |
| ---------------- | -------------------------------------------- |
| Size             | `2x1.5` and `4x4`                            |
| Egress           | No network access, so `deny_all` only        |
| Lifetime         | Up to 14 days                                |
| Pause and resume | No                                           |
| Region           | The location of your Agent Platform instance |

Snapshots, port previews, custom images, environment variables set at create, idle timeouts, and GPUs are not available on this provider. A create that asks for any other egress or size routes to another provider.

## Create an Agent Platform instance

In a Google Cloud project with billing, enable the Gemini Enterprise Agent Platform API. Then install the Agent Platform SDK and create an instance in a supported region, such as `us-central1`:

```sh
pip install "google-cloud-agentplatform>=2.0.1"
```

```python
import agentplatform

client = agentplatform.Client(project="<project>", location="<location>")
print(client.runtimes.create().api_resource.name)
```

It prints the instance's resource name, `projects/<project>/locations/<location>/reasoningEngines/<id>`, which you add with the credential.

## Create the service account key

Create a role that allows only the calls Sandcovery makes, a service account that holds it, and a JSON key for that service account:

```sh
gcloud iam roles create sandcoverySandboxUser --project=<project> \
  --title="Sandcovery Sandbox User" \
  --permissions=aiplatform.sandboxEnvironments.create,aiplatform.sandboxEnvironments.delete,aiplatform.sandboxEnvironments.execute,aiplatform.sandboxEnvironments.get,aiplatform.sandboxEnvironments.list,aiplatform.reasoningEngines.get,aiplatform.operations.list
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/sandcoverySandboxUser"
gcloud iam service-accounts keys create sandcovery-key.json \
  --iam-account=sandcovery@<project>.iam.gserviceaccount.com
```

### When your organization blocks key creation

Google blocks service account key creation by default in organizations created on or after May 3, 2024, through the `iam.managed.disableServiceAccountKeyCreation` organization policy. If the last command fails because key creation is disabled, an organization policy administrator overrides that policy on this one project. Save this as `policy.yaml`:

```yaml
name: projects/<project>/policies/iam.managed.disableServiceAccountKeyCreation
spec:
  rules:
    - enforce: false
```

Then apply it and create the key again:

```sh
gcloud org-policies set-policy policy.yaml --update-mask spec
```

The override covers only this project, so the rest of your organization still blocks key creation.

## Add the credential

In **Provider Credentials** in the [dashboard](/app/credentials), add these two fields for Google Agent Platform Code Execution:

- Service account JSON key: the whole contents of `sandcovery-key.json`
- Agent Engine resource name: the name the SDK printed when you created the instance

Sandcovery signs a token request with the key at Google's token endpoint and sends Code Execution 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 the vCPU and memory each sandbox holds to your Google Cloud billing account, per second, from its create until Sandcovery deletes it. Sandcovery's estimates and spend limits count them at Google's [list price](/providers/google).
