Mengelola template sandbox

Setiap sandbox didukung oleh template lingkungan sandbox, yang menjelaskan image container yang akan dijalankan. Template sandbox berfungsi sebagai cetak biru untuk sandbox container kustom. Halaman ini menunjukkan cara mengelola siklus proses template sandbox menggunakan Agent Platform SDK. Anda dapat mencantumkan template yang ada, melihat detailnya, atau menghapusnya jika tidak lagi diperlukan.

Untuk mengubah konfigurasi template (seperti mengubah image container), hapus template yang ada dan buat template baru dengan konfigurasi yang diperbarui.

Sebelum memulai

Untuk mengelola template sandbox, Anda memerlukan peran berikut di project:

  • Pengguna Agent Platform (roles/aiplatform.user)

Menggunakan kembali template di seluruh sandbox

Untuk Penggunaan Komputer dan sandbox shell, jika Anda tidak menentukan template, template default (DEFAULT_CONTAINER_CATEGORY_COMPUTER_USE atau DEFAULT_CONTAINER_CATEGORY_SHELL_SANDBOX) akan dibuat untuk sandbox.

Template baru dibuat selama setiap panggilan create() yang tidak menyebutkan template. Menghapus sandbox tidak akan menghapus template, jadi Anda harus menghapus template secara terpisah. Jika Anda membuat banyak sandbox, sebaiknya gunakan kembali template untuk menghemat resource.

Buat template:

from agentplatform._genai import types

template_op = client.agent_engines.sandboxes.templates.create(
    name=instance_name,
    display_name="shell-sandbox-template",
    config=types.CreateSandboxEnvironmentTemplateConfig(
        default_container_environment=types.SandboxEnvironmentTemplateDefaultContainerEnvironment(
            default_container_category=types.DefaultContainerCategory.DEFAULT_CONTAINER_CATEGORY_SHELL_SANDBOX,
        ),
    ),
)
template = template_op.response.name

Kaitkan setiap sandbox dengan template dengan menyetel sandbox_environment_template:

operation = client.sandboxes.create(
    name=instance_name,
    spec={"shell_environment": {}},
    config={
        "sandbox_environment_template": template,
        "wait_for_completion": True,
    },
)

Membuat daftar template

Untuk mencantumkan semua template sandbox yang terkait dengan instance Agent Platform:

import agentplatform

client = agentplatform.Client(project='PROJECT_ID', location='LOCATION')
instance_name = 'projects/PROJECT_ID/locations/LOCATION/reasoningEngines/INSTANCE_ID'

templates_response = client.sandboxes.templates.list(name=instance_name)

for template in templates_response.sandbox_environment_templates:
    print(template.name)

Ganti kode berikut:

  • PROJECT_ID: Project ID Cloud de Confiance Anda.
  • LOCATION: Cloud de Confiance region instance Agent Platform Anda. Lihat Wilayah yang didukung.
  • INSTANCE_ID: ID instance Agent Platform.

Melihat detail template

Untuk melihat konfigurasi template sandbox tertentu:

template_name = 'projects/PROJECT_ID/locations/LOCATION/reasoningEngines/INSTANCE_ID/SandboxEnvironmentTemplate/TEMPLATE_ID'

template = client.sandboxes.templates.get(name=template_name)
print(template)

Ganti kode berikut:

  • PROJECT_ID: Project ID Cloud de Confiance Anda.
  • LOCATION: Cloud de Confiance region instance Agent Platform Anda. Lihat Wilayah yang didukung.
  • INSTANCE_ID: ID instance Agent Platform yang berisi template sandbox Anda.
  • TEMPLATE_ID: ID template sandbox.

Melihat template sandbox

Untuk melihat template sandbox yang terkait dengan sandbox, jalankan perintah berikut:

print(sandbox.sandbox_environment_template)

Menghapus template

Untuk menghapus template sandbox:

client.sandboxes.templates.delete(name=template_name)
print("Template deleted.")