Środowiska w zarządzanych agentach

Środowiska to zarządzane piaskownice Linuxa, które zapewniają agentom odizolowane miejsce do wykonywania kodu i przechowywania plików. Są one oddzielone od kontekstu interakcji, dzięki czemu możesz ponownie użyć tego samego środowiska w wielu interakcjach lub w dowolnym momencie zacząć od nowa.

Poniższy przykład pokazuje, jak utworzyć interakcję z nowym środowiskiem zdalnym i pobrać jego identyfikator:

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Install pandas and matplotlib, verify the imports, and print the versions.",
    environment="remote",
)

print(f"Environment ID: {interaction.environment_id}")

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    agent: "antigravity-preview-05-2026",
    input: "Install pandas and matplotlib, verify the imports, and print the versions.",
    environment: "remote",
});

console.log(`Environment ID: ${interaction.environment_id}`);

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "agent": "antigravity-preview-05-2026",
    "input": "Install pandas and matplotlib, verify the imports, and print the versions.",
    "environment": "remote"
}'

Parametr environment

Parametr environment może przyjmować 3 formy:

Formularz Przykład Kiedy używać
"remote" environment="remote" Utwórz nową piaskownicę.
Identyfikator środowiska environment="env_abc123" Użyj ponownie istniejącej piaskownicy ze wszystkimi jej plikami i pakietami.
Obiekt konfiguracji environment={...} Utwórz nową piaskownicę ze źródłami, regułami sieciowymi lub z oboma tymi elementami.

Poniższe przykłady pokazują 3 sposoby użycia parametru environment.

Python

from google import genai

client = genai.Client()

# Fresh sandbox
interaction = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Write a hello world script.",
    environment="remote",
)

# Reuse an existing sandbox
interaction_2 = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Modify the script to accept a name argument.",
    environment=interaction.environment_id,
    previous_interaction_id=interaction.id,
)

# New sandbox with sources
interaction_3 = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="List all files and summarize the project.",
    environment={
        "type": "remote",
        "sources": [
            {
                "type": "repository",
                "source": "https://github.com/octocat/Spoon-Knife",
                "target": "/workspace/spoon-knife",
            }
        ],
    },
)

print(interaction.output_text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client =