एनवायरमेंट, मैनेज किए गए Linux सैंडबॉक्स होते हैं. ये एजेंट को कोड चलाने और फ़ाइलों को सेव करने के लिए, एक अलग जगह देते हैं. ये इंटरैक्शन के कॉन्टेक्स्ट से अलग होते हैं. इसलिए, एक ही एनवायरमेंट का इस्तेमाल कई इंटरैक्शन में किया जा सकता है. इसके अलावा, किसी भी समय नया एनवायरमेंट शुरू किया जा सकता है.
यहां दिए गए उदाहरण में, नए रिमोट एनवायरमेंट के साथ इंटरैक्शन बनाने और उसका आईडी वापस पाने का तरीका बताया गया है:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-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-09-2026",
input: "Install pandas and matplotlib, verify the imports, and print the versions.",
environment: "remote",
});
console.log(`Environment ID: ${interaction.environment_id}`);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Install pandas and matplotlib, verify the imports, and print the versions."))
.environment(CreateAgentInteractionEnvironment.of("remote"))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Environment ID: " + interaction.environmentId().orElse(""));
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-09-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 पैरामीटर का इस्तेमाल करने के तीन तरीके दिखाए गए हैं.
Python
from google import genai
client = genai.Client()
# Fresh sandbox
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Write a hello world script.",
environment="remote",
)
# Reuse an existing sandbox
interaction_2 = client.interactions.create(
agent="antigravity-preview-09-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-09-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 = new GoogleGenAI({});
// Fresh sandbox
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Write a hello world script.",
environment: "remote",
});
// Reuse an existing sandbox
const interaction2 = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Modify the script to accept a name argument.",
environment: interaction.environment_id,
previous_interaction_id: interaction.id,
});
// New sandbox with sources
const interaction3 = await client.interactions.create({
agent: "antigravity-preview-09-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",
},
],
},
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
// Fresh sandbox
CreateAgentInteraction params1 = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Write a hello world script."))
.environment(CreateAgentInteractionEnvironment.of("remote"))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params1)).interaction().get();
// Reuse an existing sandbox
CreateAgentInteraction params2 = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Modify the script to accept a name argument."))
.environment(CreateAgentInteractionEnvironment.of(interaction.environmentId().orElse("")))
.previousInteractionId(interaction.id().orElse(""))
.build();
Interaction interaction2 = client.interactions.create(CreateInteractionRequestBody.of(params2)).interaction().get();
// New sandbox with sources
Environment env3 = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.REPOSITORY)
.source("https://github.com/octocat/Spoon-Knife")
.target("/workspace/spoon-knife")
.build()
))
.build();
CreateAgentInteraction params3 = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("List all files and summarize the project."))
.environment(CreateAgentInteractionEnvironment.of(env3))
.build();
Interaction interaction3 = client.interactions.create(CreateInteractionRequestBody.of(params3)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
REST
# Fresh sandbox
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-09-2026",
"input": [{"type": "text", "text": "Write a hello world script."}],
"environment": "remote"
}'
# Reuse an existing sandbox (replace $ENV_ID and $INTERACTION_ID with values from the previous response)
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-09-2026\",
\"input\": [{\"type\": \"text\", \"text\": \"Modify the script to accept a name argument.\"}],
\"environment\": \"$ENV_ID\",
\"previous_interaction_id\": \"$INTERACTION_ID\"
}"
# New sandbox with sources
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-09-2026",
"input": [{"type": "text", "text": "List all files and summarize the project."}],
"environment": {
"type": "remote",
"sources": [
{
"type": "repository",
"source": "https://github.com/octocat/Spoon-Knife",
"target": "/workspace/spoon-knife"
}
]
}
}'
एनवायरमेंट को कॉन्फ़िगर करना
एजेंट को यह बताकर कि आपको क्या इंस्टॉल करना है, एनवायरमेंट सेट अप किया जा सकता है.
यह डिपेंडेंसी रिज़ॉल्यूशन और समस्या हल करने की प्रोसेस को मैनेज करता है. एनवायरमेंट तैयार होने के बाद, environment_id को सेव करें और इसे फिर से इस्तेमाल करें.
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Install pandas, matplotlib, and seaborn. Verify all imports work and print the installed versions.",
environment="remote",
)
# Reuse the configured environment
interaction_2 = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Clone https://github.com/octocat/Spoon-Knife into /workspace/tools. Run the test suite and fix any missing dependencies.",
environment=interaction.environment_id,
previous_interaction_id=interaction.id,
)
# Reuse the configured environment
interaction_3 = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Using the tools in /workspace/tools, list the files.",
environment=interaction.environment_id,
previous_interaction_id=interaction_2.id,
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Install pandas, matplotlib, and seaborn. Verify all imports work and print the installed versions.",
environment: "remote",
});
const interaction2 = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Clone https://github.com/octocat/Spoon-Knife into /workspace/tools. Run the test suite and fix any missing dependencies.",
environment: interaction.environment_id,
previous_interaction_id: interaction.id,
});
const interaction3 = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Using the tools in /workspace/tools, list the files.",
environment: interaction.environment_id,
previous_interaction_id: interaction2.id,
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateAgentInteraction params1 = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Install pandas, matplotlib, and seaborn. Verify all imports work and print the installed versions."))
.environment(CreateAgentInteractionEnvironment.of("remote"))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params1)).interaction().get();
// Reuse the configured environment
CreateAgentInteraction params2 = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Clone https://github.com/octocat/Spoon-Knife into /workspace/tools. Run the test suite and fix any missing dependencies."))
.environment(CreateAgentInteractionEnvironment.of(interaction.environmentId().orElse("")))
.previousInteractionId(interaction.id().orElse(""))
.build();
Interaction interaction2 = client.interactions.create(CreateInteractionRequestBody.of(params2)).interaction().get();
// Reuse the configured environment
CreateAgentInteraction params3 = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Using the tools in /workspace/tools, list the files."))
.environment(CreateAgentInteractionEnvironment.of(interaction.environmentId().orElse("")))
.previousInteractionId(interaction2.id().orElse(""))
.build();
Interaction interaction3 = client.interactions.create(CreateInteractionRequestBody.of(params3)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
REST
# Create interaction
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-09-2026",
"input": "Install pandas, matplotlib, and seaborn. Verify all imports work and print the installed versions.",
"environment": "remote"
}'
किसी सोर्स से माउंट करना
अगर आपको पता है कि एजेंट को किन फ़ाइलों की ज़रूरत है, तो उन्हें एक ही कॉल में माउंट करें. इसके लिए, बार-बार कॉल करने की ज़रूरत नहीं है. environment कॉन्फ़िगरेशन ऑब्जेक्ट, तीन टाइप वाली sources कलेक्शन को स्वीकार करता है:
| स्रोत प्रकार | type की कीमत का |
ब्यौरा | सीमा |
|---|---|---|---|
| Git डेटा स्टोर करने की जगह | repository |
यह यूआरएल से किसी रिपॉज़िटरी को target पर मौजूद सैंडबॉक्स में क्लोन करता है. |
500 एमबी |
| Cloud Storage | gcs |
Cloud Storage से किसी फ़ाइल या डायरेक्ट्री को target पर मौजूद सैंडबॉक्स में कॉपी करता है. |
2 GB |
| इनलाइन कॉन्टेंट | inline |
यह फ़ंक्शन, सैंडबॉक्स में मौजूद target पर किसी फ़ाइल में सामान्य टेक्स्ट कॉन्टेंट लिखता है. |
हर फ़ाइल का साइज़ 1 एमबी और कुल साइज़ 2 एमबी होना चाहिए |
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="List all files under /workspace and describe what you find.",
environment={
"type": "remote",
"sources": [
{
"type": "repository",
"source": "https://github.com/octocat/Spoon-Knife",
"target": "/workspace/spoon-knife",
},
{
"type": "gcs",
"source": "gs://cloud-samples-data/bigquery/us-states/",
"target": "/workspace/gcs-data",
},
{
"type": "inline",
"content": "# Project Notes\n\n- Analyze state population data\n- Create visualizations\n",
"target": "/workspace/notes/readme.md",
},
],
},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "List all files under /workspace and describe what you find.",
environment: {
type: "remote",
sources: [
{
type: "repository",
source: "https://github.com/octocat/Spoon-Knife",
target: "/workspace/spoon-knife",
},
{
type: "gcs",
source: "gs://cloud-samples-data/bigquery/us-states/",
target: "/workspace/gcs-data",
},
{
type: "inline",
content: "# Project Notes\n\n- Analyze state population data\n- Create visualizations\n",
target: "/workspace/notes/readme.md",
},
],
},
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
Environment env = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.REPOSITORY)
.source("https://github.com/octocat/Spoon-Knife")
.target("/workspace/spoon-knife")
.build(),
Source.builder()
.type(SourceType.GCS)
.source("gs://cloud-samples-data/bigquery/us-states/")
.target("/workspace/gcs-data")
.build(),
Source.builder()
.type(SourceType.INLINE)
.content("# Project Notes\n\n- Analyze state population data\n- Create visualizations\n")
.target("/workspace/notes/readme.md")
.build()
))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("List all files under /workspace and describe what you find."))
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
REST
# Create interaction with sources
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-09-2026",
"input": "List all files under /workspace and describe what you find.",
"environment": {
"type": "remote",
"sources": [
{
"type": "repository",
"source": "https://github.com/octocat/Spoon-Knife",
"target": "/workspace/spoon-knife"
},
{
"type": "gcs",
"source": "gs://cloud-samples-data/bigquery/us-states/",
"target": "/workspace/gcs-data"
},
{
"type": "inline",
"content": "# Project Notes\n\n- Analyze state population data\n- Create visualizations\n",
"target": "/workspace/notes/readme.md"
}
]
}
}'
दोनों तरीकों को एक साथ इस्तेमाल किया जा सकता है: जाने-पहचाने सोर्स को डिक्लेरेटिव तरीके से माउंट करें. इसके बाद, पैकेज इंस्टॉल करने या सेटअप स्क्रिप्ट चलाने के लिए, फ़ॉलो-अप इंटरैक्शन का इस्तेमाल करें. कस्टम सोर्स जोड़ते समय, रूट (/) को टारगेट के तौर पर सेट नहीं किया जा सकता. आपको हमेशा कोई सब-डायरेक्ट्री तय करनी होगी.
हुक
सैंडबॉक्स में .agents/hooks.json कॉन्फ़िगरेशन फ़ाइल और कस्टम इंटरसेप्शन स्क्रिप्ट भी माउंट की जा सकती हैं. इससे सुरक्षा से जुड़े दिशा-निर्देशों को लागू किया जा सकता है. साथ ही, जब भी टूल काम करते हैं, तब अपने-आप पुष्टि करने की सुविधा चालू की जा सकती है. स्कीमा की परिभाषाओं और कोड के उदाहरणों के लिए, हुक देखें.
निजी सोर्स
नेटवर्क कॉन्फ़िगरेशन में सोर्स डोमेन की पुष्टि करके, निजी GitHub रिपॉज़िटरी या निजी Cloud Storage बकेट से भी डाउनलोड किया जा सकता है.
एक विकल्प, आईडी के ज़रिए रेफ़र किया गया सेव किया गया क्रेडेंशियल है. इससे आपको सीक्रेट को सिर्फ़ एक बार सेव करना होता है. इसके बाद, जिस भी एनवायरमेंट को उस सोर्स की ज़रूरत होती है वह उसे रेफ़र कर सकता है:
"network": {
"allowlist": [
{ "domain": "github.com", "credential": "github-production" },
{ "domain": "*" }
]
}
यहां दिए गए उदाहरणों की तरह, transform के साथ हेडर को इनलाइन भी सेट किया जा सकता है. इग्रेस प्रॉक्सी, दोनों फ़ॉर्म को एक ही तरीके से लागू करती है. साथ ही, किसी भी मामले में सीक्रेट, सैंडबॉक्स के अंदर नहीं जाता है.
निजी Git रिपॉज़िटरी के लिए, Basic पुष्टि करने की सुविधा का इस्तेमाल करें. इसके लिए, GitHub Personal Access Token (PAT) का इस्तेमाल करें.
उपयोगकर्ता नाम के तौर पर x-oauth-basic का इस्तेमाल करके, टोकन को कोड में बदलें:
echo -n "x-oauth-basic:ghp_YourPATHere" | base64
Python
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Run the test for my backend app and fix any issue.",
environment={
"type": "remote",
"sources": [
{
"type": "repository",
"source": "https://github.com/your-org/backend",
"target": "/backend-app"
}
],
"network": {
"allowlist": [
{
"domain": "github.com",
"transform": {
"Authorization": "Basic YOUR_BASE64_TOKEN"
}
},
{
"domain": "*"
}
]
}
}
)
JavaScript
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Run the test for my backend app and fix any issue.",
environment: {
type: "remote",
sources: [
{
type: "repository",
source: "https://github.com/your-org/backend",
target: "/backend-app"
}
],
network: {
allowlist: [
{
domain: "github.com",
transform: {
"Authorization": "Basic YOUR_BASE64_TOKEN"
}
},
{
domain: "*"
}
]
}
},
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.Allowlist;
import com.google.genai.gaos.models.interactions.AllowlistEntry;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.EnvironmentNetworkEgressAllowlist;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Network;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import com.google.genai.gaos.models.interactions.Transform;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
import java.util.Map;
Client client = new Client();
Environment env = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.REPOSITORY)
.source("https://github.com/your-org/backend")
.target("/backend-app")
.build()
))
.network(Network.of(EnvironmentNetworkEgressAllowlist.of(
Allowlist.builder()
.allowlist(List.of(
AllowlistEntry.builder()
.domain("github.com")
.transform(Transform.of(Map.of(
"Authorization", "Basic YOUR_BASE64_TOKEN"
)))
.build(),
AllowlistEntry.builder()
.domain("*")
.build()
))
.build()
)))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Run the test for my backend app and fix any issue."))
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
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-09-2026",
"input": "Run the test for my backend app and fix any issue.",
"environment": {
"type": "remote",
"sources": [
{
"type": "repository",
"source": "https://github.com/your-org/backend",
"target": "/backend-app"
}
],
"network": {
"allowlist": [
{
"domain": "github.com",
"transform": {
"Authorization": "Basic YOUR_BASE64_TOKEN"
}
},
{
"domain": "*"
}
]
}
}
}'
निजी Cloud Storage बकेट के लिए, स्टैंडर्ड OAuth 2.0 बियरर टोकन का इस्तेमाल करें:
gcloud auth print-access-token
Python
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Analyze the discrepancies across the data in workspace",
environment={
"type": "remote",
"sources": [
{
"type": "gcs",
"source": "gs://my-private-bucket/data",
"target": "/workspace",
}
],
"network": {
"allowlist": [
{
"domain": "*.googleapis.com",
"transform": {
"Authorization": "Bearer YOUR_GCS_TOKEN"
}
},
{
"domain": "*"
}
]
}
},
)
JavaScript
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Analyze the discrepancies across the data in workspace",
environment: {
type: "remote",
sources: [
{
type: "gcs",
source: "gs://my-private-bucket/data",
target: "/workspace",
}
],
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
"Authorization": "Bearer YOUR_GCS_TOKEN"
}
},
{
domain: "*"
}
]
}
},
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.Allowlist;
import com.google.genai.gaos.models.interactions.AllowlistEntry;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.EnvironmentNetworkEgressAllowlist;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Network;
import com.google.genai.gaos.models.interactions.Source;
import com.google.genai.gaos.models.interactions.SourceType;
import com.google.genai.gaos.models.interactions.Transform;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
import java.util.Map;
Client client = new Client();
Environment env = Environment.builder()
.sources(List.of(
Source.builder()
.type(SourceType.GCS)
.source("gs://my-private-bucket/data")
.target("/workspace")
.build()
))
.network(Network.of(EnvironmentNetworkEgressAllowlist.of(
Allowlist.builder()
.allowlist(List.of(
AllowlistEntry.builder()
.domain("*.googleapis.com")
.transform(Transform.of(Map.of(
"Authorization", "Bearer YOUR_GCS_TOKEN"
)))
.build(),
AllowlistEntry.builder()
.domain("*")
.build()
))
.build()
)))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Analyze the discrepancies across the data in workspace"))
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
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-09-2026",
"input": "Analyze the discrepancies across the data in workspace",
"environment": {
"type": "remote",
"sources": [
{
"type": "gcs",
"source": "gs://my-private-bucket/data",
"target": "/workspace"
}
],
"network": {
"allowlist": [
{
"domain": "storage.googleapis.com",
"transform": {
"Authorization": "Bearer YOUR_GCS_TOKEN"
}
},
{
"domain": "*"
}
]
}
}
}'
पहले से इंस्टॉल किया गया सॉफ़्टवेयर
सैंडबॉक्स, Ubuntu पर चलता है. इसमें रनटाइम और सामान्य पैकेज पहले से इंस्टॉल होते हैं. एजेंट, रनटाइम के दौरान pip
install या npm install का इस्तेमाल करके अतिरिक्त पैकेज इंस्टॉल कर सकता है. किसी इंटरैक्शन के दौरान इंस्टॉल किए गए पैकेज, उसी environment_id का दोबारा इस्तेमाल करने पर भी बने रहते हैं.
| कैटगरी | पहले से इंस्टॉल किए गए पैकेज |
|---|---|
| UNIX टूल | curl, wget, git, rsync, unzip, ripgrep, fd-find, gawk, bc, tree, which, lsof, htop, jq, iproute2, procps, gcloud CLI |
| Python 3.12 | numpy, pandas, requests, google-genai, beautifulsoup4, pyyaml, ast-grep-cli |
| Node.js 22 | create-next-app, create-vite, typescript |
एनवायरमेंट वैरिएबल
सैंडबॉक्स में एनवायरमेंट वैरिएबल सेट करने के लिए, env फ़ील्ड का इस्तेमाल करें. हर एंट्री, वैरिएबल के नाम को कॉन्फ़िगरेशन के लिए लिटरल स्ट्रिंग या सीक्रेट के लिए सेव किए गए क्रेडेंशियल के रेफ़रंस से मैप करती है. एजेंट उन्हें उसी तरह से देखता है जैसे किसी शेल में दिखता है. इसलिए, प्रोसेस एनवायरमेंट से डेटा पढ़ने वाले टूल और स्क्रिप्ट, उन्हें बिना किसी अतिरिक्त वायरिंग के चुन लेते हैं.
| फ़ील्ड | टाइप | ब्यौरा |
|---|---|---|
env |
object |
वैरिएबल के नाम से वैल्यू तक का मैप. वैल्यू, लिटरल string या {"credential": "credential-id"} के फ़ॉर्मैट में क्रेडेंशियल का रेफ़रंस होती है. |
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Build the project and run the test suite.",
environment={
"type": "remote",
"env": {
"NODE_ENV": "production",
"LOG_LEVEL": "debug",
"API_TOKEN": {"credential": "my-api-token"},
},
},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Build the project and run the test suite.",
environment: {
type: "remote",
env: {
NODE_ENV: "production",
LOG_LEVEL: "debug",
API_TOKEN: { credential: "my-api-token" },
},
},
});
console.log(interaction.output_text);
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-09-2026",
"input": [{"type": "text", "text": "Build the project and run the test suite."}],
"environment": {
"type": "remote",
"env": {
"NODE_ENV": "production",
"LOG_LEVEL": "debug",
"API_TOKEN": {"credential": "my-api-token"}
}
}
}'
वेरिएबल, उस इंटरैक्शन में एजेंट की ओर से चलाई जाने वाली हर कमांड पर लागू होते हैं. इनमें शेल कमांड, बिल्ड स्टेप, और एजेंट की ओर से शुरू की गई कोई भी प्रोसेस शामिल है.
दोनों वैल्यू टाइप अलग-अलग तरीके से काम करते हैं. लिटरल स्ट्रिंग को कंटेनर में सामान्य टेक्स्ट के तौर पर लिखा जाता है. क्रेडेंशियल रेफ़रंस यह नहीं है: वैरिएबल को प्लेसहोल्डर मिलता है. साथ ही, इग्रेस प्रॉक्सी सिर्फ़ उन आउटबाउंड अनुरोधों पर असली सीक्रेट को बदलता है जो क्रेडेंशियल के भरोसेमंद डोमेन को भेजे जाते हैं. यह सुविधा कैसे काम करती है, इसके बारे में जानने के लिए क्रेडेंशियल को एनवायरमेंट वैरिएबल के तौर पर इस्तेमाल करना लेख पढ़ें.
नेटवर्क कॉन्फ़िगरेशन
डिफ़ॉल्ट रूप से, एनवायरमेंट में आउटबाउंड नेटवर्क का ऐक्सेस बिना किसी पाबंदी के होता है. network फ़ील्ड का इस्तेमाल करके, आउटबाउंड ट्रैफ़िक को कुछ डोमेन तक सीमित करें. हर नियम में एक domain तय किया जाता है. साथ ही, सेव किए गए सीक्रेट को इंजेक्ट करने के लिए एक वैकल्पिक credential और मैच करने वाली अनुरोधों में हेडर इंजेक्ट करने के लिए एक वैकल्पिक transform ऑब्जेक्ट तय किया जाता है.
ये हेडर, हर इंटरैक्शन के लिए यूनीक हो सकते हैं. साथ ही, इन्हें एक ही एनवायरमेंट के लिए अपडेट किया जा सकता है.
| फ़ील्ड | टाइप | ब्यौरा |
|---|---|---|
domain |
string |
मिलान करने के लिए डोमेन. सभी डोमेन के लिए, सटीक होस्टनेम या * का इस्तेमाल करें. |
credential |
string |
सेव किए गए क्रेडेंशियल का आईडी. ईग्रेस प्रॉक्सी इसे हल करती है और अनुरोध के समय, पुष्टि करने वाले हेडर को इंजेक्ट करती है. |
transform |
object |
यह ऑब्जेक्ट, फ़्लैट की-वैल्यू पेयर वाला होता है.यह उन हेडर को दिखाता है जिन्हें मैचिंग अनुरोधों में इंजेक्ट करना है. उदाहरण के लिए, {"Authorization": "Bearer ..."}. |
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Fetch the latest issues from the GitHub API for my-org/my-repo.",
environment={
"type": "remote",
"network": {
"allowlist": [
{
"domain": "api.github.com",
"transform": {
"Authorization": "Bearer ghp_your_github_token"
},
},
{"domain": "pypi.org"},
{"domain": "*"},
]
},
},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Fetch the latest issues from the GitHub API for my-org/my-repo.",
environment: {
type: "remote",
network: {
allowlist: [
{
domain: "api.github.com",
transform: {
"Authorization": "Bearer ghp_your_github_token"
},
},
{ domain: "pypi.org" },
{ domain: "*" },
]
}
},
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.Allowlist;
import com.google.genai.gaos.models.interactions.AllowlistEntry;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.EnvironmentNetworkEgressAllowlist;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Network;
import com.google.genai.gaos.models.interactions.Transform;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
import java.util.Map;
Client client = new Client();
Environment env = Environment.builder()
.network(Network.of(EnvironmentNetworkEgressAllowlist.of(
Allowlist.builder()
.allowlist(List.of(
AllowlistEntry.builder()
.domain("api.github.com")
.transform(Transform.of(Map.of(
"Authorization", "Bearer ghp_your_github_token"
)))
.build(),
AllowlistEntry.builder().domain("pypi.org").build(),
AllowlistEntry.builder().domain("*").build()
))
.build()
)))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Fetch the latest issues from the GitHub API for my-org/my-repo."))
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
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-09-2026",
"input": [{"type": "text", "text": "Fetch the latest issues from the GitHub API for my-org/my-repo."}],
"environment": {
"type": "remote",
"network": {
"allowlist": [
{
"domain": "api.github.com",
"transform": {
"Authorization": "Bearer ghp_your_github_token"
}
},
{"domain": "pypi.org"},
{"domain": "*"}
]
}
}
}'
अनुमति वाली सूची सेट होने पर, सिर्फ़ सूची में शामिल डोमेन के अनुरोधों को अनुमति दी जाती है. सबडोमेन से मेल खाने के लिए, वाइल्डकार्ड (जैसे, {"domain":
"*.example.com"}) का इस्तेमाल किया जा सकता है.हालांकि, ध्यान दें कि इससे रूट डोमेन example.com से मेल नहीं खाया जाता. इसे अलग से जोड़ना होगा. अन्य सभी ट्रैफ़िक को अनुमति देने के लिए, {"domain": "*"} को कैच-ऑल एंट्री के तौर पर जोड़ें. जैसे, हेडर इंजेक्ट किए बिना, सूची में शामिल नहीं किए गए डोमेन को रूट करना.
क्रेडेंशियल
आउटबाउंड ट्रैफ़िक की पुष्टि करने के दो तरीके हैं. पहला, आईडी से रेफ़र किया गया सेव किया गया क्रेडेंशियल और दूसरा, अनुमति वाली सूची के नियम में मौजूद इनलाइन transform. इग्रेस प्रॉक्सी, वायर पर लागू होती है. इसलिए, दोनों ही मामलों में सीक्रेट कभी भी सैंडबॉक्स में नहीं जाता और न ही आपके इंटरैक्शन पेलोड में दिखता है.
मैनेज किया गया क्रेडेंशियल, एक ऐसा क्रेडेंशियल होता है जिसका इस्तेमाल सीक्रेट को एक बार सेव करने और उसे फिर से इस्तेमाल करने के लिए किया जाता है. आपके प्रोजेक्ट में मौजूद हर एनवायरमेंट, एजेंट, और ट्रिगर एक ही आईडी को रेफ़रंस कर सकता है. साथ ही, इसे एक ही जगह पर रोटेट किया जा सकता है.
Python
from google import genai
client = genai.Client()
# Store the secret once
client.credentials.create(
id="github-production",
type="bearer_token",
token="ghp_your_github_token",
)
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Fetch the latest issues from the GitHub API for my-org/my-repo.",
environment={
"type": "remote",
"network": {
"allowlist": [
{"domain": "api.github.com", "credential": "github-production"},
{"domain": "*"},
]
},
},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// Store the secret once
await client.credentials.create({
id: "github-production",
type: "bearer_token",
token: "ghp_your_github_token",
});
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Fetch the latest issues from the GitHub API for my-org/my-repo.",
environment: {
type: "remote",
network: {
allowlist: [
{ domain: "api.github.com", credential: "github-production" },
{ domain: "*" },
]
}
},
});
console.log(interaction.output_text);
REST
# Store the secret once
curl -X POST "https://generativelanguage.googleapis.com/v1beta/credentials" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"id": "github-production",
"type": "bearer_token",
"token": "ghp_your_github_token"
}'
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-09-2026",
"input": "Fetch the latest issues from the GitHub API for my-org/my-repo.",
"environment": {
"type": "remote",
"network": {
"allowlist": [
{ "domain": "api.github.com", "credential": "github-production" },
{ "domain": "*" }
]
}
}
}'
oauth2 क्रेडेंशियल भी अपने ऐक्सेस टोकन को अपने-आप रीफ़्रेश करता है, ताकि टोकन की समयसीमा खत्म होने पर, लंबे समय तक चलने वाला इंटरैक्शन बंद न हो. क्रेडेंशियल के टाइप और उन्हें मैनेज करने के तरीकों की पूरी सूची देखने के लिए, क्रेडेंशियल देखें.
transform के साथ, हेडर को इनलाइन भी सेट किया जा सकता है. यह तब काम करता है, जब वैल्यू किसी एक कॉल से जुड़ी हो. उदाहरण के लिए, इंटरैक्शन बनाने से ठीक पहले जनरेट किया गया टोकन. इस तरह से सेट किए गए हेडर, एक ही इग्रेस प्रॉक्सी से इंजेक्ट किए जाते हैं.
इन्हें एनवायरमेंट वैरिएबल या फ़ाइलों के तौर पर, सैंडबॉक्स में कभी भी नहीं दिखाया जाता.
Python
import subprocess
from google import genai
# Fetch a short-lived access token from your local gcloud CLI
gcloud_token = subprocess.check_output(
["gcloud", "auth", "print-access-token"], text=True
).strip()
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="List the files in gs://my-bucket/reports/ using the GCS JSON API.",
environment={
"type": "remote",
"network": {
"allowlist": [
{
"domain": "storage.googleapis.com",
"transform": {
"Authorization": f"Bearer {gcloud_token}"
},
}
]
},
},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
import { execSync } from "child_process";
const gcloudToken = execSync("gcloud auth print-access-token").toString().trim();
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "List the files in gs://my-bucket/reports/ using the GCS JSON API.",
environment: {
type: "remote",
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
"Authorization": `Bearer ${gcloudToken}`
},
}
]
}
},
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.Allowlist;
import com.google.genai.gaos.models.interactions.AllowlistEntry;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.EnvironmentNetworkEgressAllowlist;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Network;
import com.google.genai.gaos.models.interactions.Transform;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
// Fetch a short-lived access token from your local gcloud CLI
Process process = new ProcessBuilder("gcloud", "auth", "print-access-token").start();
String gcloudToken = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8).trim();
Client client = new Client();
Environment env = Environment.builder()
.network(Network.of(EnvironmentNetworkEgressAllowlist.of(
Allowlist.builder()
.allowlist(List.of(
AllowlistEntry.builder()
.domain("storage.googleapis.com")
.transform(Transform.of(Map.of(
"Authorization", "Bearer " + gcloudToken
)))
.build()
))
.build()
)))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("List the files in gs://my-bucket/reports/ using the GCS JSON API."))
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
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-09-2026",
"input": "List the files in gs://my-bucket/reports/ using the GCS JSON API.",
"environment": {
"type": "remote",
"network": {
"allowlist": [
{
"domain": "storage.googleapis.com",
"transform": {
"Authorization": "Bearer <YOUR_GCLOUD_TOKEN>"
}
}
]
}
}
}'
credential और transform, एक ही नियम में दिख सकते हैं. क्रेडेंशियल पहले लागू होता है और transform सबसे ऊपर मर्ज होता है. इसलिए, अगर दोनों एक ही कुंजी सेट करते हैं, तो साफ़ तौर पर बताया गया transform हेडर जीत जाता है. सामान्य पैटर्न में, पुष्टि करने वाले हेडर के लिए क्रेडेंशियल और सेवा के साथ-साथ transform शामिल होता है.
नेटवर्क ऐक्सेस बंद करना
आउटबाउंड नेटवर्क के सभी ऐक्सेस को ब्लॉक करने के लिए, network को disabled पर सेट करें:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Analyze the local files only.",
environment={
"type": "remote",
"network": "disabled",
},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Analyze the local files only.",
environment: {
type: "remote",
network: "disabled",
},
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Network;
import com.google.genai.gaos.models.interactions.NetworkEnum;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
Environment env = Environment.builder()
.network(Network.of(NetworkEnum.DISABLED))
.build();
CreateAgentInteraction params = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Analyze the local files only."))
.environment(CreateAgentInteractionEnvironment.of(env))
.build();
Interaction interaction = client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
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-09-2026",
"input": "Analyze the local files only.",
"environment": {
"type": "remote",
"network": "disabled"
}
}'
क्रेडेंशियल रीफ़्रेश करना
ऐक्सेस टोकन और कम समय के लिए इस्तेमाल किए जाने वाले एपीआई पासकोड जैसे इनलाइन टोकन की समयसीमा खत्म हो जाती है.
अगले इंटरैक्शन में, मौजूदा environment_id के साथ-साथ नया network कॉन्फ़िगरेशन पास करके, उन्हें रीफ़्रेश किया जा सकता है. नई नेटवर्क सेटिंग, पिछली सेटिंग की जगह ले लेती हैं. हालांकि, एनवायरमेंट के फ़ाइल सिस्टम की स्थिति (इंस्टॉल किए गए पैकेज, फ़ाइलें, रिपॉज़िटरी) में कोई बदलाव नहीं होता.
अगर आपने सेव किए गए क्रेडेंशियल का इस्तेमाल किया है, तो आपको इसकी ज़रूरत नहीं है. oauth2 क्रेडेंशियल अपने-आप रीफ़्रेश होता है. साथ ही, किसी भी क्रेडेंशियल को रोटेट करना, क्रेडेंशियल पर PATCH होता है. इससे, अनुमति वाली सूची के हर नियम पर कोई असर नहीं पड़ता.
Python
from google import genai
client = genai.Client()
# First interaction: use an initial token
first = client.interactions.create(
agent="antigravity-preview-09-2026",
input="List the files in gs://my-bucket/reports/ using the GCS JSON API.",
environment={
"type": "remote",
"network": {
"allowlist": [
{
"domain": "storage.googleapis.com",
"transform": {
"Authorization": "Bearer INITIAL_TOKEN"
},
}
]
},
},
)
# Later: refresh the token on the same environment
result = client.interactions.create(
agent="antigravity-preview-09-2026",
input="Now download the file reports/q1.csv from the same bucket.",
environment={
"type": "remote",
"environment_id": first.environment_id,
"network": {
"allowlist": [
{
"domain": "storage.googleapis.com",
"transform": {
"Authorization": "Bearer REFRESHED_TOKEN"
},
}
]
},
},
)
print(result.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// First interaction: use an initial token
const first = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "List the files in gs://my-bucket/reports/ using the GCS JSON API.",
environment: {
type: "remote",
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
"Authorization": "Bearer INITIAL_TOKEN"
},
}
]
}
},
});
// Later: refresh the token on the same environment
const result = await client.interactions.create({
agent: "antigravity-preview-09-2026",
input: "Now download the file reports/q1.csv from the same bucket.",
environment: {
type: "remote",
environment_id: first.environment_id,
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
"Authorization": "Bearer REFRESHED_TOKEN"
},
}
]
}
},
});
console.log(result.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.interactions.Allowlist;
import com.google.genai.gaos.models.interactions.AllowlistEntry;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.interactions.Environment;
import com.google.genai.gaos.models.interactions.EnvironmentNetworkEgressAllowlist;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Network;
import com.google.genai.gaos.models.interactions.Transform;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
import java.util.Map;
Client client = new Client();
// First interaction: use an initial token
Environment initialEnv = Environment.builder()
.network(Network.of(EnvironmentNetworkEgressAllowlist.of(
Allowlist.builder()
.allowlist(List.of(
AllowlistEntry.builder()
.domain("storage.googleapis.com")
.transform(Transform.of(Map.of(
"Authorization", "Bearer INITIAL_TOKEN"
)))
.build()
))
.build()
)))
.build();
CreateAgentInteraction firstParams = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("List the files in gs://my-bucket/reports/ using the GCS JSON API."))
.environment(CreateAgentInteractionEnvironment.of(initialEnv))
.build();
Interaction first = client.interactions.create(CreateInteractionRequestBody.of(firstParams)).interaction().get();
// Later: refresh the token on the same environment
Environment refreshedEnv = Environment.builder()
.environmentId(first.environmentId().orElse(""))
.network(Network.of(EnvironmentNetworkEgressAllowlist.of(
Allowlist.builder()
.allowlist(List.of(
AllowlistEntry.builder()
.domain("storage.googleapis.com")
.transform(Transform.of(Map.of(
"Authorization", "Bearer REFRESHED_TOKEN"
)))
.build()
))
.build()
)))
.build();
CreateAgentInteraction secondParams = CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-09-2026"))
.input(InteractionsInput.of("Now download the file reports/q1.csv from the same bucket."))
.environment(CreateAgentInteractionEnvironment.of(refreshedEnv))
.build();
Interaction result = client.interactions.create(CreateInteractionRequestBody.of(secondParams)).interaction().get();
System.out.println(result.outputText().orElse(""));
REST
# Use the environment_id from a previous interaction
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-09-2026",
"input": "Now download the file reports/q1.csv from the same bucket.",
"environment": {
"type": "remote",
"environment_id": "<ENVIRONMENT_ID_FROM_PREVIOUS_INTERACTION>",
"network": {
"allowlist": [
{
"domain": "storage.googleapis.com",
"transform": {
"Authorization": "Bearer REFRESHED_TOKEN"
}
}
]
}
}
}'
एनवायरमेंट का लाइफ़साइकल
एनवायरमेंट का लाइफ़साइकल इस तरह होता है:
| राज्य | व्यवहार |
|---|---|
| बनाया गया | यह तब उपलब्ध कराया जाता है, जब इंटरैक्शन में environment: "remote" या कॉन्फ़िगरेशन ऑब्जेक्ट के बारे में बताया गया हो. |
| चालू है | यह कुकी तब काम करती है, जब कोई इंटरैक्शन प्रोसेस में होता है. |
| कुछ समय से इस्तेमाल में नहीं है | ऑटो-स्नैपशॉट की सुविधा चालू है और 15 मिनट तक कोई गतिविधि न होने पर यह बंद हो जाती है. |
| ऑफ़लाइन | पिछली बार ऐक्टिव रहने के बाद से सात दिनों तक सेव रहता है. इसका आईडी पास करके इसे फिर से शुरू किया जा सकता है. |
| मिटाया गया | टीटीएल की सात दिनों की अवधि खत्म होने के बाद, यह डेटा सिस्टम से अपने-आप हट जाता है. इसके अलावा, इसे मैन्युअल तरीके से भी मिटाया जा सकता है. |
Environments API
सैंडबॉक्स सेशन को प्रोग्राम के हिसाब से मैनेज करने के लिए, Environments API का इस्तेमाल किया जा सकता है. एनवायरमेंट की गिनती करने से, आपको चालू सेशन आईडी का पता चलता है. साथ ही, लंबे समय तक चलने वाले टास्क के दौरान क्लाइंट कनेक्शन बंद होने पर, आपको स्थिति वापस लाने में मदद मिलती है. सेशन के मेटाडेटा की जांच भी की जा सकती है. साथ ही, वर्कफ़्लो पूरा होने पर एनवायरमेंट को साफ़ तौर पर मिटाया जा सकता है. इसके लिए, टीटीएल के अपने-आप खत्म होने का इंतज़ार करने की ज़रूरत नहीं होती.
एनवायरमेंट की सूची बनाना
आपके प्रोजेक्ट से जुड़े चालू एनवायरमेंट की सूची बनाता है. जवाब के बैच के साइज़ को कंट्रोल करने के लिए, पेज नंबर के पैरामीटर इस्तेमाल करें.
Python
from google import genai
client = genai.Client()
response = client.environments.list(page_size=10)
for env in response.environments:
print(f"Environment ID: {env.id}, Status: {env.status}")
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const response = await client.environments.list({ page_size: 10 });
for (const env of response.environments) {
console.log(`Environment ID: ${env.id}, Status: ${env.status}`);
}
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.environments.Environment;
import com.google.genai.gaos.models.environments.ListEnvironmentsResponse;
import java.util.List;
Client client = new Client();
ListEnvironmentsResponse response = client.environments.listEnvironments()
.pageSize(10)
.call()
.listEnvironmentsResponse()
.get();
for (Environment env : response.environments().orElse(List.of())) {
System.out.println("Environment ID: " + env.id().orElse("") + ", Status: " + env.status().orElse(null));
}
REST
curl -X GET "https://generativelanguage.googleapis.com/v1beta/environments?pageSize=10" \
-H "x-goog-api-key: $GEMINI_API_KEY"
जवाब कुछ ऐसा दिखता है:
{
"environments": [
{
"id": "140128b2a13c12c00a5a0d8cf7af9469",
"status": "active"
},
{
"id": "362b738275a1d74af6f1c62bc050da73",
"status": "active"
}
],
"next_page_token": "Cj...5aE="
}
एनवायरमेंट पाना
किसी एनवायरमेंट के लिए, मेटाडेटा और कॉन्फ़िगरेशन की जानकारी पाएं. इसके लिए, एनवायरमेंट के संसाधन का नाम इस्तेमाल करें.
Python
from google import genai
client = genai.Client()
env = client.environments.get(id="YOUR_ENVIRONMENT_ID")
print(f"Environment ID: {env.id}, Status: {env.status}")
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const env = await client.environments.get("YOUR_ENVIRONMENT_ID");
console.log(`Environment ID: ${env.id}, Status: ${env.status}`);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.environments.Environment;
Client client = new Client();
Environment env = client.environments.getEnvironment("YOUR_ENVIRONMENT_ID").environment().get();
System.out.println("Environment ID: " + env.id().orElse("") + ", Status: " + env.status().orElse(null));
REST
curl -X GET "https://generativelanguage.googleapis.com/v1beta/environments/YOUR_ENVIRONMENT_ID" \
-H "x-goog-api-key: $GEMINI_API_KEY"
जवाब कुछ ऐसा दिखता है:
{
"id": "140128b2a13c12c00a5a0d8cf7af9469",
"status": "active",
"sources": [
{
"type": "repository",
"source": "https://github.com/octocat/Spoon-Knife",
"target": "/workspace/spoon-knife"
}
],
"network": {
"allowlist": [
{
"domain": "api.github.com"
},
{
"domain": "github.com"
}
]
}
}
किसी एनवायरमेंट को मिटाना
टास्क या पाइपलाइन पूरी होने के बाद, सैंडबॉक्स के संसाधनों को हटाने के लिए, एनवायरमेंट को साफ़ तौर पर बंद करें और मिटाएं.
Python
from google import genai
client = genai.Client()
client.environments.delete(id="YOUR_ENVIRONMENT_ID")
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
await client.environments.delete("YOUR_ENVIRONMENT_ID");
Java
import com.google.genai.Client;
Client client = new Client();
client.environments.deleteEnvironment("YOUR_ENVIRONMENT_ID");
REST
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/environments/YOUR_ENVIRONMENT_ID" \
-H "x-goog-api-key: $GEMINI_API_KEY"
एनवायरमेंट में फ़ाइलों को मैनेज करना
एजेंट, सैंडबॉक्स में फ़ाइलें बनाता है और उन्हें बदलता है. आपके पास डायरेक्ट्री का कॉन्टेंट ब्राउज़ करने, फ़ाइल का मेटाडेटा पाने, अलग-अलग फ़ाइलों या पूरी डायरेक्ट्री को टार आर्काइव के तौर पर डाउनलोड करने, और फ़ाइलों को अपलोड करने या आर्काइव को सीधे एनवायरमेंट में निकालने का विकल्प होता है. सैंडबॉक्स एनवायरमेंट में स्टोरेज का इस्तेमाल, उचित इस्तेमाल की सीमाओं के मुताबिक किया जाता है.
किसी डायरेक्ट्री में मौजूद फ़ाइलों की सूची बनाना
एनवायरमेंट में मौजूद किसी डायरेक्ट्री का कॉन्टेंट दिखाता है. डिफ़ॉल्ट रूप से, रूट डायरेक्ट्री की सूची दिखाता है.
क्वेरी पैरामीटर
| पैरामीटर | टाइप | ब्यौरा |
|---|---|---|
recursive |
बूलियन | true विकल्प का इस्तेमाल करने पर, सभी फ़ाइलों और डायरेक्ट्री की सूची दिखती है. डिफ़ॉल्ट: false. |
Python
from google import genai
client = genai.Client()
# List root directory
response = client.environments.files.list(
environment="YOUR_ENVIRONMENT_ID",
path="",
)
for file in response.files:
print(f"{file.name} ({file.type}) - {file.path}")
# List a subdirectory recursively
response = client.environments.files.list(
environment="YOUR_ENVIRONMENT_ID",
path="src",
recursive=True,
)
for file in response.files:
print(f"{file.name} ({file.type}) - {file.path}")
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// List root directory
const response = await client.environments.files.list({
environment: "YOUR_ENVIRONMENT_ID",
path: "",
});
for (const file of response.files) {
console.log(`${file.name} (${file.type}) - ${file.path}`);
}
// List a subdirectory recursively
const srcResponse = await client.environments.files.list({
environment: "YOUR_ENVIRONMENT_ID",
path: "src",
recursive: true,
});
for (const file of srcResponse.files) {
console.log(`${file.name} (${file.type}) - ${file.path}`);
}
REST
# List root directory
curl -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files" \
-H "x-goog-api-key: $GEMINI_API_KEY"
# List a subdirectory
curl -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files/src" \
-H "x-goog-api-key: $GEMINI_API_KEY"
# List all files recursively
curl -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files?recursive=true" \
-H "x-goog-api-key: $GEMINI_API_KEY"
जवाब में, files ऐरे मिलता है. इसमें हर एंट्री के लिए मेटाडेटा होता है:
{
"files": [
{
"name": "config",
"path": "config",
"type": "DIRECTORY",
"created": "2026-08-12T07:44:18Z",
"modified": "2026-08-12T07:44:18Z"
},
{
"name": "main.py",
"path": "src/main.py",
"type": "FILE",
"size_bytes": "15",
"mime_type": "text/x-python; charset=utf-8",
"created": "2026-08-12T07:44:20Z",
"modified": "2026-08-12T07:44:20Z"
}
]
}
फ़ाइल एंट्री फ़ील्ड
| फ़ील्ड | टाइप | ब्यौरा |
|---|---|---|
name |
स्ट्रिंग | फ़ाइल या डायरेक्ट्री का नाम. |
path |
स्ट्रिंग | एनवायरमेंट रूट के हिसाब से पूरा पाथ. |
type |
स्ट्रिंग | FILE या DIRECTORY में से कोई एक वैल्यू दी जानी चाहिए. |
size_bytes |
स्ट्रिंग | फ़ाइल का साइज़, बाइट में (सिर्फ़ फ़ाइलों के लिए). |
mime_type |
स्ट्रिंग | एमआईएमई टाइप (सिर्फ़ फ़ाइलों के लिए). |
created |
स्ट्रिंग | आईएसओ 8601 फ़ॉर्मैट में, वर्शन बनाए जाने का टाइमस्टैंप. |
modified |
स्ट्रिंग | ISO 8601 के मुताबिक, बदलाव किए जाने का आखिरी टाइमस्टैंप. |
फ़ाइल का मेटाडेटा पाना
पाथ के हिसाब से, किसी फ़ाइल का मेटाडेटा पाएं.
Python
from google import genai
client = genai.Client()
response = client.environments.files.list(
environment="YOUR_ENVIRONMENT_ID",
path="src/main.py",
)
file = response.files[0]
print(f"Name: {file.name}, Size: {file.size_bytes} bytes, Type: {file.mime_type}")
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const response = await client.environments.files.list({
environment: "YOUR_ENVIRONMENT_ID",
path: "src/main.py",
});
const file = response.files[0];
console.log(`Name: ${file.name}, Size: ${file.size_bytes} bytes, Type: ${file.mime_type}`);
REST
curl -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files/src/main.py" \
-H "x-goog-api-key: $GEMINI_API_KEY"
जवाब में, फ़ाइल का मेटाडेटा files कलेक्शन में शामिल होता है:
{
"files": [
{
"name": "main.py",
"path": "src/main.py",
"type": "FILE",
"size_bytes": "15",
"mime_type": "text/x-python; charset=utf-8",
"created": "2026-08-12T07:44:20Z",
"modified": "2026-08-12T07:44:20Z"
}
]
}
अगर फ़ाइल मौजूद नहीं है, तो एपीआई 404 गड़बड़ी का मैसेज दिखाता है:
{
"error": {
"message": "Path 'nonexistent.txt' not found in environment 'ENV_ID'.",
"code": "not_found"
}
}
एक फ़ाइल डाउनलोड करना
किसी फ़ाइल का कॉन्टेंट डाउनलोड करें. एसडीके में, download()
तरीके का इस्तेमाल करें. REST अनुरोधों में, फ़ाइल के पाथ में ?alt=media क्वेरी पैरामीटर जोड़ें. सर्वर, 200 OK के साथ जवाब देता है और फ़ाइल के कॉन्टेंट को स्ट्रीम करता है.
Python
from google import genai
client = genai.Client()
content = client.environments.files.download(
environment="YOUR_ENVIRONMENT_ID",
path="src/main.py",
)
with open("main.py", "wb") as f:
f.write(content)
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "fs";
const client = new GoogleGenAI({});
const bytes = await client.environments.files.download({
environment: "YOUR_ENVIRONMENT_ID",
path: "src/main.py",
});
fs.writeFileSync("main.py", Buffer.from(bytes));
REST
curl -L -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files/src/main.py?alt=media" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-o main.py
किसी डायरेक्ट्री को टार संग्रह के तौर पर डाउनलोड करना
?alt=media के साथ डायरेक्ट्री का पाथ भेजकर, पूरी डायरेक्ट्री को टार संग्रह के तौर पर डाउनलोड करें. इससे POSIX tar फ़ाइल मिलती है (gzipped नहीं). नेस्ट की गई सबडाइरेक्ट्री शामिल करने के लिए, recursive=true का इस्तेमाल करें.
Python
import tarfile
from google import genai
client = genai.Client()
# Download a subdirectory archive
archive = client.environments.files.download(
environment="YOUR_ENVIRONMENT_ID",
path="src",
)
with open("src.tar", "wb") as f:
f.write(archive)
with tarfile.open("src.tar") as tar:
tar.extractall(path="./extracted")
JavaScript
import { GoogleGenAI } from "@google/genai";
import { execSync } from "child_process";
import * as fs from "fs";
const client = new GoogleGenAI({});
// Download a subdirectory archive
const bytes = await client.environments.files.download({
environment: "YOUR_ENVIRONMENT_ID",
path: "src",
});
fs.writeFileSync("src.tar", Buffer.from(bytes));
execSync("tar -xf src.tar -C ./extracted");
REST
# Download a subdirectory (top-level files only)
curl -L -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files/src?alt=media" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-o src.tar
# Download a subdirectory recursively (includes nested directories)
curl -L -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files/config?alt=media&recursive=true" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-o config.tar
# Download root directory
curl -L -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files?alt=media" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-o snapshot.tar
# Extract the archive
tar xf snapshot.tar -C ./extracted
व्यवहार मैट्रिक्स
यहां दी गई मैट्रिक्स में, फ़ाइल और डायरेक्ट्री एंडपॉइंट, एचटीटीपी तरीके, और क्वेरी पैरामीटर के हिसाब से, जवाब और संग्रह के व्यवहार के बारे में खास जानकारी दी गई है:
| अनुरोध | alt |
recursive |
extract |
overwrite |
जवाब |
|---|---|---|---|---|---|
GET /files |
(कुछ नहीं) | (कुछ नहीं) | - | - | रूट डायरेक्ट्री की JSON फ़ाइल में मौजूद लिस्टिंग |
GET /files/{path} (फ़ाइल) |
(कुछ नहीं) | - | - | - | फ़ाइल के लिए JSON मेटाडेटा |
GET /files/{path} (dir) |
(कुछ नहीं) | false |
- | - | तुरंत बाद आने वाले बच्चों की JSON फ़ाइल में सूची |
GET /files/{path} (dir) |
(कुछ नहीं) | true |
- | - | सभी डिसेंडेंट की JSON लिस्टिंग |
GET /files/{path}?alt=media (फ़ाइल) |
media |
- | - | - | फ़ाइल का रॉ कॉन्टेंट |
GET /files/{path}?alt=media (dir) |
media |
false |
- | - | डायरेक्ट्री में मौजूद फ़ाइलों का टार संग्रह |
GET /files/{path}?alt=media (dir) |
media |
true |
- | - | सभी फ़ाइलों का Tar संग्रह |
GET /files?alt=media |
media |
false |
- | - | सिर्फ़ रूट-लेवल की फ़ाइलों का Tar संग्रह |
PUT /files/{path} (फ़ाइल) |
- | - | false |
false |
यह फ़ंक्शन, फ़ाइल को पाथ पर लिखता है. अगर 409 Conflict पहले से मौजूद है, तो उसे दिखाता है |
PUT /files/{path}?overwrite=true |
- | - | false |
true |
इस फ़ंक्शन का इस्तेमाल, पाथ पर मौजूद फ़ाइल में लिखने या उसे बदलने के लिए किया जाता है |
PUT /files/{path}?extract=true |
- | - | true |
false |
यह विकल्प, डेस्टिनेशन डायरेक्ट्री में संग्रह को अनपैक करता है. अगर कोई टारगेट फ़ाइल मौजूद है, तो 409 Conflict दिखाता है |
PUT /files/{path}?extract=true&overwrite=true |
- | - | true |
true |
यह विकल्प, आर्काइव को अनपैक करता है और मौजूदा फ़ाइलों को बदल देता है |
एनवायरमेंट में फ़ाइलें अपलोड करना
HTTP PUT का इस्तेमाल करके, अलग-अलग फ़ाइलें या डायरेक्ट्री संग्रह सीधे किसी मौजूदा एनवायरमेंट सैंडबॉक्स में अपलोड करें. अगर पैरंट डायरेक्ट्री मौजूद नहीं हैं, तो उन्हें अपने-आप बना दिया जाता है. एनवायरमेंट में स्टोरेज, फ़ेयर यूज़ की सीमाओं के मुताबिक होता है.
एक फ़ाइल अपलोड करना
Python
from google import genai
client = genai.Client()
with open("local_file.txt", "rb") as f:
result = client.environments.files.upload(
environment="YOUR_ENVIRONMENT_ID",
path="workspace/data/file.txt",
file=f,
mime_type="text/plain",
overwrite=True,
)
file = result.files[0]
print(f"Uploaded: {file.name} ({file.size_bytes} bytes)")
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "fs";
const client = new GoogleGenAI({});
const content = fs.readFileSync("local_file.txt");
const result = await client.environments.files.upload({
environment: "YOUR_ENVIRONMENT_ID",
path: "workspace/data/file.txt",
file: content,
mime_type: "text/plain",
overwrite: true,
});
const file = result.files[0];
console.log(`Uploaded: ${file.name} (${file.size_bytes} bytes)`);
REST
curl -X PUT "https://generativelanguage.googleapis.com/upload/v1beta/environments/$ENV_ID/files/workspace/data/file.txt" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: text/plain" \
--data-binary @local_file.txt
जवाब में, अपलोड की गई फ़ाइल का मेटाडेटा मिलता है. इसे सूची और get एंडपॉइंट के साथ एक जैसा रखने के लिए, files ऐरे में रैप किया जाता है:
{
"files": [
{
"name": "file.txt",
"path": "workspace/data/file.txt",
"type": "FILE",
"size_bytes": "1024",
"mime_type": "text/plain"
}
]
}
किसी डायरेक्ट्री के संग्रह को अपलोड और एक्सट्रैक्ट करना
एक ही अनुरोध में पूरे कोड बेस या डायरेक्ट्री स्ट्रक्चर को सीड करने के लिए, extract=true के साथ .tar या .tar.gz संग्रह अपलोड करें.
Python
from google import genai
client = genai.Client()
with open("source.tar.gz", "rb") as f:
result = client.environments.files.upload(
environment="YOUR_ENVIRONMENT_ID",
path="workspace/src/",
file=f,
extract=True,
)
for entry in result.files:
print(f"Extracted: {entry.path}")
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "fs";
const client = new GoogleGenAI({});
const archive = fs.readFileSync("source.tar.gz");
const result = await client.environments.files.upload({
environment: "YOUR_ENVIRONMENT_ID",
path: "workspace/src/",
file: archive,
extract: true,
});
for (const entry of result.files) {
console.log(`Extracted: ${entry.path}`);
}
REST
curl -X PUT "https://generativelanguage.googleapis.com/upload/v1beta/environments/$ENV_ID/files/workspace/src/?extract=true" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/x-tar" \
--data-binary @source.tar.gz
जवाब में, संग्रह की गई हर फ़ाइल की सूची दी गई है:
{
"files": [
{
"name": "app.py",
"path": "workspace/src/app.py",
"type": "FILE",
"size_bytes": "15",
"mime_type": "text/x-python"
},
{
"name": "requirements.txt",
"path": "workspace/src/requirements.txt",
"type": "FILE",
"size_bytes": "17",
"mime_type": "text/plain"
}
]
}
फिर से शुरू किए जा सकने वाले सेशन की मदद से बड़ी फ़ाइलें अपलोड करना
बड़े पेलोड के लिए या कमज़ोर कनेक्शन से अपलोड करते समय, एक ही अनुरोध में पूरा डेटा भेजने के बजाय, फिर से शुरू किए जा सकने वाले सेशन का इस्तेमाल करें. फिर से शुरू किए जा सकने वाले अपलोड में, ट्रांसफ़र को ऐसे हिस्सों में बांटा जाता है जिन्हें अलग-अलग तौर पर फिर से आज़माया जा सकता है. इसलिए, ट्रांसफ़र के बीच में गड़बड़ी होने पर, आपको शुरू से ट्रांसफ़र करने की ज़रूरत नहीं पड़ती.
uploadType=resumable के साथ सेशन शुरू करें. खाली बॉडी भेजें. साथ ही, अपलोड किए जाने वाले मीडिया टाइप और पेलोड के कुल साइज़ के बारे में बताने के लिए, X-Upload-Content-Type और X-Upload-Content-Length हेडर का इस्तेमाल करें:
PUT /upload/v1beta/environments/$ENV_ID/files/workspace/data/large_dataset.bin?uploadType=resumable HTTP/1.1
Host: generativelanguage.googleapis.com
X-Upload-Content-Type: application/octet-stream
X-Upload-Content-Length: 20971520
Content-Length: 0
x-goog-api-key: $GEMINI_API_KEY
जवाब में, Location हेडर में सेशन का यूआरएल होता है. इस यूआरएल में पहले से ही upload_id मौजूद है. इसलिए, इसे फिर से एपीआई पासकोड की ज़रूरत नहीं है:
HTTP/1.1 200 OK
Location: https://generativelanguage.googleapis.com/upload/v1beta/environments/$ENV_ID/files/workspace/data/large_dataset.bin?uploadType=resumable&upload_id=AJjja9bfHjiYlGi60pUazCaTuPY
Content-Length: 0
उस यूआरएल पर पेलोड को हिस्सों में अपलोड करें. हर चंक, Content-Range हेडर के साथ अपने बाइट रेंज और कुल साइज़ का एलान करता है:
PUT /upload/v1beta/environments/$ENV_ID/files/workspace/data/large_dataset.bin?uploadType=resumable&upload_id=AJjja9bfHjiYlGi60pUazCaTuPY HTTP/1.1
Host: generativelanguage.googleapis.com
Content-Type: application/octet-stream
Content-Range: bytes 0-10485759/20971520
Content-Length: 10485760
<10 MB binary payload>
आखिरी हिस्से को छोड़कर, हर हिस्से में 308 Resume Incomplete दिखता है. Range हेडर से पता चलता है कि सर्वर ने कितने बाइट प्रोसेस किए हैं. अगर कोई हिस्सा अपलोड नहीं होता है, तो आपको यहीं से अपलोड करना होगा:
HTTP/1.1 308 Resume Incomplete
Range: bytes=0-10485759
Content-Length: 0
बचे हुए हिस्सों को इसी तरह भेजें:
PUT /upload/v1beta/environments/$ENV_ID/files/workspace/data/large_dataset.bin?uploadType=resumable&upload_id=AJjja9bfHjiYlGi60pUazCaTuPY HTTP/1.1
Host: generativelanguage.googleapis.com
Content-Type: application/octet-stream
Content-Range: bytes 10485760-20971519/20971520
Content-Length: 10485760
<remaining 10 MB binary payload>
आखिरी चंक, अपलोड करने की प्रोसेस पूरी करता है और फ़ाइल का मेटाडेटा दिखाता है. यह मेटाडेटा, सिंगल-शॉट अपलोड की तरह ही files एनवलप में दिखता है:
{
"files": [
{
"name": "large_dataset.bin",
"path": "workspace/data/large_dataset.bin",
"type": "FILE",
"size_bytes": "20971520",
"mime_type": "application/octet-stream"
}
]
}
फिर से शुरू किए जा सकने वाले सेशन, extract और overwrite के साथ भी काम करते हैं. उन क्वेरी पैरामीटर को, शुरू किए गए अनुरोध पर सेट करें, न कि अलग-अलग हिस्सों पर.
ओवरराइट सुरक्षा
डिफ़ॉल्ट रूप से, overwrite की वैल्यू false होती है. अगर डेस्टिनेशन पाथ पहले से मौजूद है, तो अनुरोध में 409 Conflict गड़बड़ी दिखती है और कुछ भी नहीं लिखा जाता:
{
"error": {
"message": "Requested entity already exists",
"code": "aborted"
}
}
किसी मौजूदा फ़ाइल या डायरेक्ट्री को बदलने के लिए, overwrite=true सेट करें (या REST में ?overwrite=true जोड़ें). extract=true का इस्तेमाल करने पर, संग्रह में मौजूद हर फ़ाइल के लिए टकराव की जांच की जाती है. इसलिए, अगर कोई टारगेट फ़ाइल मौजूद है, तो अनुरोध पूरा नहीं किया जा सकता.
पूरा स्नैपशॉट डाउनलोड करें (अब इस्तेमाल नहीं किया जाता)
मौजूदा कोड को Environment Files API पर माइग्रेट करने के लिए:
Python: फ़ाइल डाउनलोड करने के पुराने अनुरोधों को इससे बदलें:
archive = client.environments.files.download( environment="YOUR_ENVIRONMENT_ID", path="workspace", ) with open("snapshot.tar", "wb") as f: f.write(archive)JavaScript: फ़ाइल डाउनलोड करने के लेगसी अनुरोधों को इससे बदलें:
const bytes = await client.environments.files.download({ environment: "YOUR_ENVIRONMENT_ID", path: "workspace", }); fs.writeFileSync("snapshot.tar", Buffer.from(bytes));REST:
GET /v1beta/files/environment-$ENV_ID:download?alt=mediaको इससे बदलें:curl -L -X GET "https://generativelanguage.googleapis.com/v1beta/environments/$ENV_ID/files?alt=media" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -o snapshot.tar
कीमत और संसाधन
हर एनवायरमेंट के लिए, संसाधनों का तय हिस्सा इस्तेमाल किया जाता है:
| संसाधन | वैल्यू |
|---|---|
| सीपीयू | 4 कोर |
| मेमोरी | 16 जीबी |
प्रीव्यू पीरियड के दौरान, एनवायरमेंट कंप्यूट (सीपीयू, मेमोरी, सैंडबॉक्स एक्ज़ीक्यूशन) के लिए बिल नहीं भेजा जाता. एजेंट टोकन की लागत के लिए, कीमत देखें.
सीमाएं
- प्रीव्यू का स्टेटस: एनवायरमेंट और मैनेज किए गए एजेंट, प्रीव्यू में हैं. सुविधाओं और स्कीमा में बदलाव हो सकता है.
- इनलाइन सोर्स का साइज़: इनलाइन सोर्स के लिए, हर फ़ाइल का साइज़ 1 एमबी से ज़्यादा नहीं होना चाहिए. साथ ही, सभी फ़ाइलों का कुल साइज़ 2 एमबी से ज़्यादा नहीं होना चाहिए.
- सोर्स का साइज़: Git रिपॉज़िटरी का साइज़ 500 एमबी और Cloud Storage रिपॉज़िटरी का साइज़ 2 जीबी से ज़्यादा नहीं होना चाहिए.
- एनवायरमेंट स्टार्टअप: नया एनवायरमेंट उपलब्ध कराने में ~5 सेकंड लगते हैं. सोर्स रिपॉज़िटरी बड़ी होने पर, इसमें ज़्यादा समय लग सकता है.
- एनवायरमेंट की समयसीमा खत्म होना: ऑफ़लाइन एनवायरमेंट में कोई गतिविधि न होने पर, उन्हें सात दिनों तक सेव रखा जाता है. इसके बाद, टीटीएल की अपने-आप होने वाली प्रोसेस का इस्तेमाल करके, उन्हें मिटा दिया जाता है. समयसीमा खत्म हो चुके या अमान्य एनवायरमेंट आईडी को पास करने पर,
404 Not Foundगड़बड़ी दिखती है. - फ़ाइल फ़ॉर्मैट: फ़िलहाल, एजेंट सिर्फ़ टेक्स्ट और इमेज फ़ाइलें पढ़ सकता है. फ़िलहाल, बाइनरी फ़ाइल का इस्तेमाल नहीं किया जा सकता.
- रूट से माउंट नहीं किया जा सकता: कस्टम सोर्स जोड़ते समय, रूट (
/) को टारगेट के तौर पर सेट नहीं किया जा सकता. आपको हमेशा कोई सब-डायरेक्ट्री तय करनी होगी.
आगे क्या करना है
- एजेंट की खास जानकारी: मैनेज किए जाने वाले एजेंट के मुख्य सिद्धांतों के बारे में जानें.
- क्विकस्टार्ट: सिलसिलेवार बातचीत और स्ट्रीमिंग की सुविधा का इस्तेमाल शुरू करें.
- Antigravity Agent: डिफ़ॉल्ट एजेंट की सुविधाओं, टूल, मॉडल चुनने के विकल्प, और कीमत के बारे में जानें.
- कस्टम एजेंट बनाना:
AGENTS.mdऔरSKILL.mdका इस्तेमाल करके, अपने एजेंट तय करें. - हुक: सैंडबॉक्स में सुरक्षा से जुड़े दिशा-निर्देश लागू करें और साइड इफ़ेक्ट की पुष्टि करें.