محیطها، سندباکسهای لینوکس مدیریتشدهای هستند که به عاملها مکانی ایزوله برای اجرای کد و ذخیره فایلها میدهند. آنها از زمینه تعامل جدا هستند، بنابراین میتوانید از همان محیط در چندین تعامل استفاده مجدد کنید یا در هر زمان از نو شروع کنید.
مثال زیر نحوه ایجاد تعامل با یک محیط ریموت جدید و بازیابی شناسه آن را نشان میدهد:
پایتون
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}")
جاوا اسکریپت
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}`);
استراحت
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"
}'
پارامتر environment
پارامتر environment سه حالت را میپذیرد:
| فرم | مثال | چه زمانی استفاده شود |
|---|---|---|
"remote" | environment="remote" | یک گودال ماسهای تازه تهیه کنید. |
| شناسه محیط | environment="env_abc123" | استفاده مجدد از یک سندباکس موجود به همراه تمام فایلها و بستههای آن. |
| شیء پیکربندی | environment={...} | یک سندباکس جدید با منابع، قوانین شبکه یا هر دو فراهم کنید. |
مثالهای زیر سه روش استفاده از پارامتر environment را نشان میدهند.
پایتون
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)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// Fresh sandbox
const interaction = await