Gemini Environments API

Environments provide isolated execution contexts for running agent code, tools, and services securely.

CreateEnvironment

post https://generativelanguage.googleapis.com/v1beta/environments

Creates an environment.

Request body

The request body contains data with the following structure:

from_environment string  (optional)

Optional. The source environment to copy/fork from. Format: `environments/{environment_id}` or `{environment_id}`. When specified, `sources` and `env` must be empty.

network EnvironmentNetworkEgressAllowlist or enum (string)  (optional)

Network configuration for the environment.

Outbound networking configuration for the sandbox. Accepts an object with an 'allowlist' array to restrict traffic, or the string 'disabled' to turn off all network access. Omit entirely to allow all outbound traffic with no header injection.

Possible Types

object

Outbound networking configuration for the sandbox. When specified, restricts which external domains the sandbox can reach. Omit entirely to allow all outbound traffic with no header injection.

allowlist array (AllowlistEntry)  (optional)

List of allowed outbound domains. Only requests to listed domains are permitted. Use [{'domain': '*'}] to allow all domains while still injecting headers on specific ones.

A single domain allowlist rule with optional header injection.

Fields

credential string  (optional)

Optional. Reference to a server-managed Credential resource by ID.

domain string  (optional)

Domain to allow outbound requests to. Supports wildcards (e.g. '*.googleapis.com'). Use '*' to allow all domains.

transform array (object) or object  (optional)

Headers to inject on all outbound requests matching this domain. Accepts a single dict or a list of dicts. The egress proxy injects these automatically.

string

Turns all network off.

Possible values

  • disabled

    Turns all network off.

sources array (Source)  (optional)

Sources to be mounted into the environment.

A source to be mounted into the environment.

Fields

content string  (optional)

The inline content if `type` is `INLINE`.

encoding string  (optional)

Optional encoding for inline content (e.g. `base64`).

source string  (optional)

The source of the environment. For Cloud Storage, this is the Cloud Storage path. For GitHub, this is the GitHub path.

target string  (optional)

Where the source should appear in the environment.

type enum (string)  (optional)

No description provided.

Possible values:

  • gcs

    A Cloud Storage bucket.

  • inline

    Inline content.

  • repository

    A generic repository. The protocol prefix in the source URL identifies the provider (e.g., github://, gcs://).

Response

If successful, the response body contains data with the following structure:

created string  (optional)

Output only. The time at which the environment was created in ISO 8601 format (YYYY-MM-DDThh:mm:ssZ).

file_count string  (optional)

Output only. The number of files in the environment, output only.

id string  (optional)

Required. Output only. The ID of the environment.

last_accessed string  (optional)

Output only. The time at which the environment was last accessed in ISO 8601 format (YYYY-MM-DDThh:mm:ssZ).

network EnvironmentNetworkEgressAllowlist or enum (string)  (optional)

Network configuration for the environment.

Outbound networking configuration for the sandbox. Accepts an object with an 'allowlist' array to restrict traffic, or the string 'disabled' to turn off all network access. Omit entirely to allow all outbound traffic with no header injection.

Possible Types

object

Outbound networking configuration for the sandbox. When specified, restricts which external domains the sandbox can reach. Omit entirely to allow all outbound traffic with no header injection.

allowlist array (AllowlistEntry)  (optional)

List of allowed outbound domains. Only requests to listed domains are permitted. Use [{'domain': '*'}] to allow all domains while still injecting headers on specific ones.

A single domain allowlist rule with optional header injection.

Fields

credential string  (optional)

Optional. Reference to a server-managed Credential resource by ID.

domain string  (optional)

Domain to allow outbound requests to. Supports wildcards (e.g. '*.googleapis.com'). Use '*' to allow all domains.

transform array (object) or object  (optional)

Headers to inject on all outbound requests matching this domain. Accepts a single dict or a list of dicts. The egress proxy injects these automatically.

string

Turns all network off.

Possible values

  • disabled

    Turns all network off.

size_bytes string  (optional)

Output only. The total size of the environment files in bytes, output only.

sources array (Source)  (optional)

Sources to be mounted into the environment.

A source to be mounted into the environment.

Fields

content string  (optional)

The inline content if `type` is `INLINE`.

encoding string  (optional)

Optional encoding for inline content (e.g. `base64`).

source string  (optional)

The source of the environment. For Cloud Storage, this is the Cloud Storage path. For GitHub, this is the GitHub path.