### Install Go Client SDK Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/go/README.md Install the Go client SDK for Agent Sandbox using go get. ```bash go get sigs.k8s.io/agent-sandbox/clients/go/sandbox ``` -------------------------------- ### Run Basic Python Example Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/aio-sandbox/README.md Execute the main Python script to interact with the AIO Sandbox using the installed SDK. Ensure the virtual environment is activated. ```sh python3 main.py ``` -------------------------------- ### Install Async Extras Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md Install the necessary extras for asynchronous client functionality. ```bash pip install k8s-agent-sandbox[async] ``` -------------------------------- ### Langchain Agent Example Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/use-cases/examples/langchain/_index.md This example demonstrates a basic Langchain agent setup for use with agent-sandbox. It requires Langchain and agent-sandbox to be installed. ```python from langchain_core.tools import tool from langgraph.graph import StateGraph, END from typing import TypedDict, Annotated import operator from langchain_core.messages import AIMessage, HumanMessage @tool def get_weather(city: str) -> str: """Returns the weather for a city.""" return f"The weather in {city} is sunny." @tool def get_stock_price(symbol: str) -> str: """Returns the stock price for a given symbol.""" return f"The stock price for {symbol} is $100." class AgentState(TypedDict): messages: Annotated[list, operator.add] class CodingAgent(object): def __init__(self): self.tools = [get_weather, get_stock_price] def __call__(self, state: AgentState): messages = state['messages'] message = messages[-1] if isinstance(message, AIMessage): for tool in self.tools: if tool.name in message.content: output = tool.invoke(message.content.split(":")[1].strip()) return "continue", AIMessage(content=output) return END, None workflow = StateGraph(AgentState) workflow.add_node("agent", CodingAgent()) workflow.set_entry_point("agent") app = workflow.compile() inputs = {"messages": [HumanMessage("What is the weather in Paris?")]} for s in app.stream(inputs): print(s) ``` -------------------------------- ### Install Kyverno Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/policy/kyverno/README.md Installs Kyverno using Helm into the 'kyverno' namespace, creating the namespace if it doesn't exist. ```bash # 3. Install Kyverno helm install kyverno kyverno/kyverno --namespace kyverno --create-namespace ``` -------------------------------- ### Install and Use setup-envtest Tool Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/policy/vap/README.md Installs the setup-envtest tool and downloads the Kubernetes API server binary required for local testing. Ensure your Go version meets the requirements. ```bash go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest # This downloads the correct kube-apiserver and etcd for your OS/Arch go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use 1.30 go: downloading sigs.k8s.io/controller-runtime v0.23.1 go: downloading sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20260216173200-e4c1c38bcbdb go: sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20260216173200-e4c1c38bcbdb requires go >= 1.25.0; switching to go1.25.7 go: downloading github.com/spf13/afero v1.12.0 go: downloading go.uber.org/multierr v1.10.0 go: downloading golang.org/x/text v0.33.0 Version: 1.30.0 OS/Arch: linux/amd64 Path: /your/path/.local/share/kubebuilder-envtest/k8s/1.30.0-linux-amd64 ``` -------------------------------- ### VS Code Sandbox Example Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/use-cases/examples/kata-containers/_index.md This snippet is part of the VS Code Sandbox README. It likely contains setup or usage instructions for the sandbox environment, but the actual code is not present in the provided context. ```markdown {{% include-file file="additional/examples/vscode-sandbox/README.md" %}} ``` -------------------------------- ### Install Agent Sandbox Client from Source (Editable Mode) Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md Install the client in editable mode after cloning the repository. Include optional tracing dependencies if needed. ```bash cd ~ git clone https://github.com/kubernetes-sigs/agent-sandbox.git cd agent-sandbox/clients/python/agentic-sandbox-client pip install -e . ``` ```bash pip install -e ".[tracing]" ``` -------------------------------- ### Install Agent Sandbox Client from PyPI Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md Install the client package from PyPI. Use the optional tracing dependencies for GCP integration. ```bash pip install k8s-agent-sandbox ``` ```bash pip install "k8s-agent-sandbox[tracing]" ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/composing-sandbox-nw-policies/README.md Clone the agent-sandbox repository and navigate to its directory to access the example files. ```bash # Clone the repository git clone https://github.com/kubernetes-sigs/agent-sandbox.git # Navigate to the repository directory cd agent-sandbox ``` -------------------------------- ### Install Agent Sandbox Client from Git Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md Install the client from source via git. Replace 'main' with a specific version tag for pinning. This method uses setuptools-scm for dynamic versioning. ```bash # Replace "main" with a specific version tag (e.g., "v0.1.0") from # https://github.com/kubernetes-sigs/agent-sandbox/releases to pin a version tag. export VERSION="main" pip install "git+https://github.com/kubernetes-sigs/agent-sandbox.git@${VERSION}#subdirectory=clients/python/agentic-sandbox-client" ``` -------------------------------- ### Resource Metrics Example Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/sandbox/metrics/_index.md Example of resource metrics tracking internal client latency. ```json { "resource_metrics": [ { "resource": { "attributes": { "telemetry.sdk.language": "python", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.41.0", "telemetry.auto.version": "0.62b0", "service.name": "unknown_service" }, "schema_url": "" }, "scope_metrics": [ { "metrics": [ { "name": "http.client.request.duration", "description": "Measures the duration of HTTP client requests.", "unit": "s", "data": { "type": "histogram", "data_points": [ { "time_unix_nano": 1775816163476643000, "count": 1, "sum": 35.0, "bucket_counts": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], "explicit_bounds": [ 0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0 ], "min": 35, "max": 35, "exemplars": [ { "filtered_attributes": {}, "value": 35, "time_unix_nano": 1775816163476643000, "span_id": 4637909099667112766, "trace_id": 27019542480527418515130145646832490510 } ] } ], "aggregation_temporality": 2 } } ], "schema_url": "https://opentelemetry.io/schemas/1.11.0" } ], "schema_url": "" } ] } ``` -------------------------------- ### Hello World Example in Go Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/use-cases/examples/python-sdk-quickstart/_index.md A basic 'Hello, World!' program in Go. This snippet demonstrates the fundamental structure of a Go program. ```go package main import "fmt" func main() { fmt.Println("Hello, World!") } ``` -------------------------------- ### Run Setup Script for Kata Containers Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/kata-gke-sandbox/README.md Executes the setup script to prepare the environment for Kata Containers on GKE. Refer to the script for available options. ```shell ./setup.sh [OPTIONS...] ``` -------------------------------- ### Async Direct Connection Example Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md Demonstrates creating and using an AsyncSandboxClient with a direct connection configuration. Requires an explicit API URL. ```python import asyncio from k8s_agent_sandbox import AsyncSandboxClient from k8s_agent_sandbox.models import SandboxDirectConnectionConfig async def main(): config = SandboxDirectConnectionConfig( api_url="http://sandbox-router-svc.default.svc.cluster.local:8080" ) async with AsyncSandboxClient(connection_config=config) as client: sandbox = await client.create_sandbox( template="python-sandbox-template", namespace="default", ) result = await sandbox.commands.run("echo 'Hello from async!'") print(result.stdout) asyncio.run(main()) ``` -------------------------------- ### Automated Setup and Test for KinD Gateway Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/gateway-kind/README.md Executes a script to automate the entire setup and testing process for Gateway API support on a KinD cluster. ```bash ./run-test-kind.sh ``` -------------------------------- ### Install Python Agentic Sandbox Client Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/python-client/_index.md Install the Python client library using pip. This is the first step to using the client in your projects. ```bash pip install python-agentic-sandbox-client ``` -------------------------------- ### JupyterLab Deployment Example Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/use-cases/examples/jupyterlab/_index.md This example demonstrates a basic deployment of JupyterLab on Agent-Sandbox. Ensure you have the necessary configurations and permissions before applying. ```yaml apiVersion: agent.sandbox.cloud.google.com/v1alpha1 kind: JupyterLab metadata: name: jupyterlab-sample spec: # Specify the image to use for the JupyterLab environment. # Example: "jupyter/base-notebook:latest" image: "jupyter/datascience-notebook:latest" # Define resource requests and limits for the pod. resources: requests: cpu: "500m" memory: "1Gi" limits: cpu: "1" memory: "2Gi" # Optionally, specify environment variables for the container. # env: # - name: "MY_VARIABLE" # value: "my_value" # Optionally, mount volumes for persistent storage or configuration. # volumes: # - name: "my-volume" # persistentVolumeClaim: # claimName: "my-pvc" # volumeMounts: # - name: "my-volume" # mountPath: "/home/jovyan/work" ``` -------------------------------- ### Install k8s_agent_sandbox SDK Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/volumes/volume-claim-template/_index.md Install the k8s_agent_sandbox Python package using pip. ```bash pip install k8s_agent_sandbox ``` -------------------------------- ### Basic Helm Installation Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/helm/README.md Installs the Agent Sandbox Helm chart with default settings. Ensure you replace `` with the desired controller image tag. ```bash helm install agent-sandbox ./helm/ \ --namespace agent-sandbox-system \ --create-namespace \ --set image.tag= ``` -------------------------------- ### Install KRO Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/composing-sandbox-nw-policies/README.md Install KRO on your Kubernetes cluster using the provided installation script. ```bash ./dev/tools/install-kro ``` -------------------------------- ### Install ResourceGraphDefinition (RGD) Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/composing-sandbox-nw-policies/README.md Install the RGD for the `AgenticSandbox` CRD. This defines the composite resource that KRO will manage. ```bash # Switch to the examples directory cd examples/composing-sandbox-nw-policies # Install the RGD kubectl apply -f rgd.yaml ``` -------------------------------- ### Environment Configuration Options Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/python-client/_index.md Shows how to specify custom configurations when creating an environment, such as image and entrypoint. This allows for more tailored sandbox setups. ```python from agentic_sandbox.client import AgenticSandboxClient client = AgenticSandboxClient() # Create an environment with a specific image and entrypoint custom_env_response = client.create_environment( environment_name="custom-env", image="ubuntu:latest", entrypoint=["/bin/bash", "-c"] ) print(f"Custom environment created: {custom_env_response}") # Run a command using the custom entrypoint run_custom_response = client.run_command(environment_name="custom-env", command="echo 'Custom entrypoint works!'") print(f"Custom command output: {run_custom_response}") client.delete_environment(environment_name="custom-env") ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/gemini-cu-sandbox/README.md Install the necessary Python libraries for the agent sandbox. This includes 'kubernetes' and 'requests'. ```bash pip install kubernetes requests ``` -------------------------------- ### Install Kind Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/runtime-templates/computer-use/_index.md Installs Kind, a tool for running local Kubernetes clusters using Docker. This is a prerequisite for deploying the agent sandbox locally. ```bash GO111MODULE=on go get github.com/kubernetes-sigs/kind@v0.20.1 ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/jupyterlab/README.md Clone the agent-sandbox repository and navigate to the jupyterlab example directory. ```bash git clone https://github.com/kubernetes-sigs/agent-sandbox.git cd agent-sandbox/examples/jupyterlab ``` -------------------------------- ### Verify Required Software Installations Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/langchain/README.md Check if the necessary software versions (Go, Make, Python, Docker, Kind, kubectl) are installed on your system. ```bash # Verify installations go version # Go 1.19+ make --version # GNU Make python3 --version # Python 3.13+ docker --version # Docker 20.10+ kind --version # Kind 0.17+ kubectl version --client # kubectl 1.25+ ``` -------------------------------- ### Start Minikube with Kata Support Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/use-cases/kata-containers-isolation/_index.md Initialize a minikube cluster using the KVM2 driver and containerd runtime, which is required for Kata Containers. ```sh minikube start --vm-driver kvm2 --memory 8192 --container-runtime=containerd --bootstrapper=kubeadm ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/k8s_agent_sandbox/extensions/README.md Sets up a Python virtual environment named '.venv' from the project root directory. Activate the environment using the provided source command. ```bash # From the project root directory python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/ray-integration/README.md Installs the necessary Python libraries, including Ray and the Agent Sandbox SDK, for integrating with the sandbox environment. ```bash pip install ray k8s-agent-sandbox ``` -------------------------------- ### Python SDK Example for Volume Persistence Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/volumes/volume-claim-template/_index.md Demonstrates creating a sandbox, writing data to a persistent volume, retrieving the sandbox by claim name, and verifying the data survived. ```python from k8s_agent_sandbox import SandboxClient validation_message = "volume validation" client = SandboxClient() sandbox1 = client.create_sandbox("simple-sandbox-template") response1 = sandbox1.commands.run(f"sh -c \"echo '{validation_message}' > /data/volume_validation.txt\"") print(f"Claim Name: {sandbox1.claim_name}") client2 = SandboxClient() sandbox2 = client2.get_sandbox(sandbox1.claim_name) response2 = sandbox2.commands.run(f"sh -c \"cat /data/volume_validation.txt\"") assert response2.stdout.strip() == validation_message, f"\"{response2.stdout.strip()}\" != \"{validation_message}\"." print(f"response2.stdout.strip(): {response2.stdout.strip()}") sandbox2.terminate() ``` -------------------------------- ### Deploy cloud-provider-kind Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/gateway-kind/README.md Installs the latest version of cloud-provider-kind and runs it in the background to enable the Gateway API controller for KinD clusters. ```bash make deploy-cloud-provider-kind ``` -------------------------------- ### Install Dependencies Dynamically Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/sandbox/custom_sandbox/image/_index.md Use the `sandbox.commands.run()` function to install Python packages into a sandbox before executing your main logic. This is useful for sandboxes that require specific dependencies not included in the base image. ```python from k8s_agent_sandbox import SandboxClient client = SandboxClient() sandbox = client.create_sandbox("python-sandbox-template") # Dynamically install a package before running your main logic sandbox.commands.run("pip install custom-package==1.0.0") response = sandbox.commands.run("python -c 'import custom_package; print(\"Success!\")'") ``` -------------------------------- ### Install Python SDK (Editable) Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/quickstart/README.md Installs the agentic-sandbox-client Python SDK in editable mode within a virtual environment. Keep the environment activated for subsequent commands. ```bash python3 -m venv .venv source .venv/bin/activate pip install -e clients/python/agentic-sandbox-client ``` -------------------------------- ### Run Sandbox Client with Tracing Enabled Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/GCP.md Instantiate the SandboxClient with `enable_tracing=True` to generate and send traces. This example shows basic sandbox creation and command execution. ```python from k8s_agent_sandbox import SandboxClient def main(): # ... sb = SandboxClient(tracer_config=SandboxTracerConfig(enable_tracing=True)) sandbox = sb.create_sandbox(template="python-sandbox-template") try: sandbox.commands.run("echo 'Hello, World!'") finally: sandbox.terminate() if __name__ == "__main__": main() ``` -------------------------------- ### Install ADK and Agent Sandbox Client Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/code-interpreter-agent-on-adk/README.md Installs the necessary Python packages, including the Agent Development Kit and the Agent Sandbox client. Ensure the VERSION is set correctly. ```shell export VERSION="main" pip install google-adk==1.19.0 "git+https://github.com/kubernetes-sigs/agent-sandbox.git@${VERSION}#subdirectory=clients/python/agentic-sandbox-client" ``` -------------------------------- ### Wait for VSCode to Start Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/vscode-sandbox/README.md Monitor pod logs to confirm the VSCode server is listening. This indicates the initialization process is complete. ```bash kubectl logs -f sandbox-example ``` -------------------------------- ### Set Sandbox and Router Image References Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/quickstart/README.md Export environment variables for the router image and sandbox namespace. These are used throughout the quickstart process. ```bash export ROUTER_IMAGE=sandbox-router:local export SANDBOX_NAMESPACE=agent-sandbox-demo export SANDBOX_TEMPLATE_NAME=python-runtime-template ``` -------------------------------- ### Start Minikube with Containerd Runtime Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/vscode-sandbox/README.md Start a Minikube cluster using the KVM2 driver, specifying 8192MB memory and the 'containerd' runtime. This configuration is recommended for Kata Containers. ```shell minikube start --vm-driver kvm2 --memory 8192 --container-runtime=containerd --bootstrapper=kubeadm ``` -------------------------------- ### JupyterLab Experiment Setup Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/use-cases/examples/isolated-ml-workspaces/_index.md This snippet shows the configuration for setting up an isolated JupyterLab environment for ML experiments using Agent-Sandbox. It includes necessary imports and basic setup. ```go package main import ( "context" "fmt" "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" // Import the AgentSandbox types "github.com/kubernetes-sigs/agent-sandbox/api/v1alpha1" ) func main() { ctx := context.Background() // Initialize logger log.SetLogger(logr.Discard()) logger := log.FromContext(ctx) // Setup Kubernetes client config := rest.InClusterConfig() scheme := runtime.NewScheme() runtime.Must(v1alpha1.AddToScheme(scheme)) c, err := client.New(config, client.Options{Scheme: scheme}) if err != nil { logger.Error(err, "failed to create client") return } // Define the ML Workspace mlWorkspace := &v1alpha1.MLWorkspace{ // Specify the namespace and name // For example: //メタdata: { // Namespace: "default", // Name: "my-ml-workspace", //}, } // Create the ML Workspace in the cluster if err := c.Create(ctx, mlWorkspace); err != nil { logger.Error(err, "failed to create MLWorkspace") return } fmt.Printf("MLWorkspace %s/%s created successfully\n", mlWorkspace.Namespace, mlWorkspace.Name) } ``` -------------------------------- ### Hello World Example in Python Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/use-cases/examples/python-sdk-quickstart/_index.md A basic 'Hello, World!' program in Python. This snippet demonstrates the fundamental structure of a Python script. ```python def main(): print("Hello, World!") if __name__ == "__main__": main() ``` -------------------------------- ### Async In-Cluster Connection Example Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md Shows how to use the AsyncSandboxClient for in-cluster connections, which defaults to using cluster DNS. No explicit URL is needed. ```python import asyncio from k8s_agent_sandbox import AsyncSandboxClient from k8s_agent_sandbox.models import SandboxInClusterConnectionConfig async def main(): config = SandboxInClusterConnectionConfig() # default: cluster DNS async with AsyncSandboxClient(connection_config=config) as client: sandbox = await client.create_sandbox( template="python-sandbox-template", namespace="default", ) result = await sandbox.commands.run("echo 'Hello from async!'") print(result.stdout) asyncio.run(main()) ``` -------------------------------- ### Initialize and Manage Multiple Sandboxes Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/go/README.md Demonstrates how to create a new sandbox client, enable auto-cleanup, create multiple sandboxes, list active sandboxes, and re-attach to an existing sandbox by its claim name. ```go client, err := sandbox.NewClient(ctx, sandbox.Options{}) // Initialize client stop := client.EnableAutoCleanup() // Enable automatic cleanup on SIGINT/SIGTERM deferr stop() deferr client.DeleteAll(ctx) // Ensure all sandboxes are deleted on exit sb1, _ := client.CreateSandbox(ctx, "python-template", "default") // Create first sandbox sb2, _ := client.CreateSandbox(ctx, "node-template", "default") // Create second sandbox // List tracked sandboxes for _, key := range client.ListActiveSandboxes() { fmt.Printf(" %s/%s\n", key.Namespace, key.ClaimName) } // Re-attach to existing sandbox by claim name sb, _ := client.GetSandbox(ctx, sb1.ClaimName(), "default") ``` -------------------------------- ### Example Telemetry Data (JSON) Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/sandbox/metrics/_index.md This JSON payload contains resource metrics collected by the OpenTelemetry SDK. It includes details about the SDK's configuration, such as language, version, and service name, as well as specific metrics like log queue capacity and started spans. ```json { "resource_metrics": [ { "resource": { "attributes": { "telemetry.sdk.language": "python", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.41.0", "telemetry.auto.version": "0.62b0", "service.name": "unknown_service" }, "schema_url": "" }, "scope_metrics": [ { "scope": { "name": "opentelemetry-sdk", "version": null, "schema_url": "", "attributes": null }, "metrics": [ { "name": "otel.sdk.processor.log.queue.capacity", "description": "The maximum number of log records the queue of a given instance of an SDK Log Record processor can hold.", "unit": "{log_record}", "data": { "data_points": [ { "attributes": { "otel.component.type": "batching_log_processor", "otel.component.name": "batching_log_processor/0" }, "start_time_unix_nano": 1775816160885369000, "time_unix_nano": 1775816163498738000, "value": 2048, "exemplars": [] } ], "aggregation_temporality": 2, "is_monotonic": false } }, { "name": "otel.sdk.span.started", "description": "The number of created spans.", "unit": "{span}", "data": { "data_points": [ { "attributes": { "otel.span.parent.origin": "none", "otel.span.sampling_result": "RECORD_AND_SAMPLE" }, "start_time_unix_nano": 1775816163440787000, "time_unix_nano": 1775816163498738000, "value": 1, "exemplars": [] } ], "aggregation_temporality": 2, "is_monotonic": true } }, { "name": "otel.sdk.span.live", "description": "The number of created spans with `recording=true` for which the end operation has not been called yet.", "unit": "{span}", "data": { "data_points": [ { "attributes": { "otel.span.sampling_result": "RECORD_AND_SAMPLE" }, "start_time_unix_nano": 1775816163440787000, "time_unix_nano": 1775816163498738000, "value": 0, "exemplars": [] } ], "aggregation_temporality": 2, "is_monotonic": false } } ] } ] } ] } ``` -------------------------------- ### Basic Python Client Usage Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/python-client/_index.md Demonstrates the fundamental steps to initialize and use the Python client. This includes creating a client instance and making a simple request. ```python from agentic_sandbox.client import AgenticSandboxClient # Initialize the client client = AgenticSandboxClient() # Example: List available environments response = client.list_environments() print(response) ``` -------------------------------- ### Create Sandbox Instance Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/docs/keps/359-refactor-python-sdk/README.md Provisions a new sandbox instance from a specified template. This example shows creation without using a context manager. ```python sbx = client.create_sandbox(template="python-ml") ``` -------------------------------- ### Create Basic KIND Kubernetes Cluster Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/quickstart/README.md Create a basic KIND cluster for Agent Sandbox. This is the default setup; alternative secure runtimes are available. ```bash kind create cluster --name agent-sandbox-demo ``` -------------------------------- ### Span Object Example Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/sandbox/metrics/_index.md Example of a Span object detailing the duration of an HTTP request. ```json { "name": "POST", "context": { "trace_id": "0x1453c64bd669390ef0b73508e6ef980e", "span_id": "0x405d29c0e235c33e", "trace_state": "[]" }, "kind": "SpanKind.CLIENT", "parent_id": null, "start_time": "2026-04-10T10:16:03.441094Z", "end_time": "2026-04-10T10:16:03.477336Z", "status": { "status_code": "UNSET" }, "attributes": { "http.method": "POST", "http.url": "http://127.0.0.1:52059/execute", "user_agent.original": "python-requests/2.33.1", "http.status_code": 200 }, "events": [], "links": [], "resource": { "attributes": { "telemetry.sdk.language": "python", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.41.0", "telemetry.auto.version": "0.62b0", "service.name": "unknown_service" }, "schema_url": "" } } ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/sandbox-router/README.md Creates and activates a Python virtual environment for project dependencies. This is a standard practice for managing Python project isolation. ```bash python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Setup Agent Sandbox Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/hpa-swp-scaling/README.md Apply the necessary Kubernetes manifests to set up the agent sandbox environment. This includes creating a namespace and applying template and warm pool configurations. ```bash kubectl create namespace hpa-test kubectl apply -f python-sandbox-template.yaml kubectl apply -f sandboxwarmpool.yaml ``` -------------------------------- ### Create ConfigMap for Initialization Files (Method B) Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/jupyterlab/README.md Create a ConfigMap containing Python scripts and notebooks for the modular deployment method. ```bash kubectl create configmap jupyter-init-files \ --from-file=files/download_models.py \ --from-file=files/requirements.txt \ --from-file=files/welcome.ipynb \ --namespace=default ``` -------------------------------- ### Example Network Policy Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/use-cases/examples/network-policies/_index.md This is an example of a Kubernetes NetworkPolicy resource that restricts ingress traffic. ```yaml apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-frontend namespace: default spec: podSelector: matchLabels: app: backend policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: app: frontend ports: - protocol: TCP port: 8080 ``` -------------------------------- ### Initialize Client and Create Sandbox Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/k8s_agent_sandbox/extensions/README.md Initializes the ComputerUseSandboxClient and creates a sandbox with computer use support. Ensure the server port matches the agent's listening port. The sandbox is created using a specified template and namespace. ```python from k8s_agent_sandbox.extensions.computer_use import ComputerUseSandboxClient from k8s_agent_sandbox.models import SandboxLocalTunnelConnectionConfig # Initialize the client targeting the specific port the agent listens on (e.g., 8888) client = ComputerUseSandboxClient( connection_config=SandboxLocalTunnelConnectionConfig(server_port=8888) ) # Create the sandbox with computer use support enabled sandbox = client.create_sandbox( template="sandbox-python-computeruse-template", namespace="default" ) ``` -------------------------------- ### Write and Execute a File in a Sandbox Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/python-sdk-quickstart/README.md This example shows how to create a sandbox, write a Python script file into its filesystem, execute the script using the `python3` command, print the script's output, and then terminate the sandbox. This is useful for running more complex logic within the sandbox environment. ```python sandbox = client.create_sandbox( template="python-sandbox-template", namespace="default", ) try: sandbox.files.write( "hello.py", 'print("Hello, World! Greetings from inside the sandbox.")\n', ) result = sandbox.commands.run("python3 hello.py") print(result.stdout) # Hello, World! Greetings from inside the sandbox. finally: sandbox.terminate() ``` -------------------------------- ### Initialize Client and Trigger Snapshot Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/k8s_agent_sandbox/gke_extensions/snapshots/README.md Demonstrates initializing the PodSnapshotSandboxClient, creating a sandbox with snapshot capabilities, triggering a manual snapshot, suspending the sandbox (with an optional snapshot), resuming it, and finally terminating the sandbox. Ensure the client is initialized and the sandbox template is available. ```python from k8s_agent_sandbox.gke_extensions.snapshots import PodSnapshotSandboxClient # Initialize the specialized snapshot client client = PodSnapshotSandboxClient() # Create a sandbox with snapshot capabilities enabled sandbox = client.create_sandbox( template="python-counter-template", namespace="default" ) try: # Trigger a manual snapshot via the snapshots engine response = sandbox.snapshots.create("my-first-snapshot") if response.success: print(f"Snapshot created successfully! UID: {response.snapshot_uid}") else: print(f"Snapshot failed: {response.error_reason}") # Suspend the sandbox (automatically takes a snapshot and scales to 0 replicas) print("Suspending sandbox...") suspend_response = sandbox.suspend(snapshot_before_suspend=True) if suspend_response.success: print("Sandbox suspended successfully.") # Resume the sandbox (scales to 1 replica and restores from the latest snapshot) print("Resuming sandbox...") resume_response = sandbox.resume() if resume_response.success: print(f"Sandbox resumed! Restored from snapshot: {resume_response.restored_from_snapshot}") finally: sandbox.terminate() ``` -------------------------------- ### Install OPA Gatekeeper Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/policy/opa-gatekeeper/README.md Installs OPA Gatekeeper into its own namespace using Helm. Ensure the namespace 'gatekeeper-system' is created. ```bash helm install gatekeeper/gatekeeper --name-template=gatekeeper --namespace gatekeeper-system --create-namespace ``` -------------------------------- ### Install the Agent Sandbox Python SDK Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/getting_started/python-sdk-quickstart/_index.md Install the necessary Python package for the Agent Sandbox SDK. This command should be run in your terminal. ```bash pip install "agent-sandbox>=0.1.0" ``` -------------------------------- ### Create and Run an Environment Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/python-client/_index.md Shows how to create a new sandbox environment and execute a command within it. This is useful for testing and running isolated processes. ```python from agentic_sandbox.client import AgenticSandboxClient client = AgenticSandboxClient() # Create a new environment create_response = client.create_environment(environment_name="my-test-env") print(f"Environment created: {create_response}") # Run a command in the environment run_response = client.run_command(environment_name="my-test-env", command="echo Hello, Sandbox!") print(f"Command output: {run_response}") # Clean up the environment client.delete_environment(environment_name="my-test-env") ``` -------------------------------- ### Set up Test Scenario ServiceAccount Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/policy/kyverno/README.md Applies the Kubernetes resources defined in '.chainsaw-tests/setup-sa.yaml' to prepare for testing. ```bash kubectl apply -f .chainsaw-tests/setup-sa.yaml ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/k8s_agent_sandbox/extensions/README.md Installs necessary Python packages, including 'kubernetes' and 'requests', and the local 'k8s_agent_sandbox' client in editable mode. ```bash pip install kubernetes requests pip install -e clients/python/agentic-sandbox-client/ ``` -------------------------------- ### Install Agent Sandbox Controller Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/runtime-templates/computer-use/_index.md Installs the agent sandbox controller into the 'gemini-cu-sandbox' Kubernetes cluster. This controller manages the runtime sandbox environment. ```bash kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/agent-sandbox/main/deploy/agent-sandbox-controller.yaml ``` -------------------------------- ### Accepting Handle Interface for Testability Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/go/README.md Shows how to design functions to accept the `sandbox.Handle` interface for easier testing with mock implementations. Includes opening the sandbox, deferring close, and running a command. ```go // Accept the narrow Handle interface for testability. func ProcessInSandbox(ctx context.Context, sb sandbox.Handle) error { if err := sb.Open(ctx); err != nil { return err } defer sb.Close(context.Background()) result, err := sb.Run(ctx, "echo hello") // ... } ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/k8s_agent_sandbox/gke_extensions/snapshots/README.md Installs the necessary Python packages for Kubernetes interaction and the agentic sandbox client. Ensure the virtual environment is activated. ```bash pip install kubernetes pip install -e clients/python/agentic-sandbox-client/ ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/sandbox-router/README.md Installs the necessary Python dependencies for the project and testing tools. This includes the project itself in editable mode and testing frameworks. ```bash pip install -e ../ pip install -r requirements.txt pip install pytest ``` -------------------------------- ### Check Init Container Logs Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/jupyterlab/README.md Command to check the logs of the init container (`setup-environment`) for troubleshooting. This is useful when the init container fails. ```bash kubectl logs jupyterlab-sandbox -c setup-environment ``` -------------------------------- ### Install agent-sandbox Python SDK Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/aio-sandbox/README.md Set up a Python virtual environment and install the agent-sandbox package. This SDK is for controlling tools within the AIO sandbox. ```sh # set up a virtual environment if needed python3 -m venv venv source venv/bin/activate # install the agent-sandbox package pip install agent-sandbox==0.0.18 ``` -------------------------------- ### Install Core Agent Sandbox Components Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/README.md Installs the core agent-sandbox controller and CRDs. Replace 'vX.Y.Z' with a specific version tag from the releases page. ```bash # Replace "vX.Y.Z" with a specific version tag (e.g., "v0.1.0") from # https://github.com/kubernetes-sigs/agent-sandbox/releases export VERSION="vX.Y.Z" # To install only the core components: kubectl apply -f https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${VERSION}/manifest.yaml ``` -------------------------------- ### Create Sandbox Client (Production Mode) Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/go/README.md Initialize a new sandbox client for production mode using Gateway API. The client automatically discovers the Gateway address. Ensure the Gateway resource exists and is accessible. ```go client, err := sandbox.NewClient(ctx, sandbox.Options{ GatewayName: "external-http-gateway", GatewayNamespace: "default", }) if err != nil { log.Fatal(err) } defer client.DeleteAll(ctx) sb, err := client.CreateSandbox(ctx, "my-sandbox-template", "default") if err != nil { log.Fatal(err) } result, err := sb.Run(ctx, "echo 'Hello from Cloud!'") if err != nil { log.Fatal(err) } fmt.Println(result.Stdout) ``` -------------------------------- ### Create and Interact with Agent Sandbox using Go SDK Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/site/content/docs/getting_started/go-sdk-quickstart/_index.md This snippet demonstrates how to use the Agent Sandbox Go SDK to create a sandbox, run a command inside it, and perform file operations. Ensure you have the necessary prerequisites and the Go client installed. ```go package main import ( "context" "fmt" "log" "sigs.k8s.io/agent-sandbox/clients/go/sandbox" ) func main() { ctx := context.Background() templateName := "my-sandbox-template" // Create client with shared configuration. client, err := sandbox.NewClient(ctx, sandbox.Options{ TemplateName: templateName, Namespace: "default", }) if err != nil { log.Fatal(err) } stop := client.EnableAutoCleanup() defer stop() defer client.DeleteAll(ctx) // Create a sandbox. sb, err := client.CreateSandbox(ctx, templateName, "default") if err != nil { log.Fatal(err) } fmt.Printf("Sandbox ready: claim=%s sandbox=%s pod=%s\n", sb.ClaimName(), sb.SandboxName(), sb.PodName()) // Run a command. result, err := sb.Run(ctx, "echo 'Hello from Go!'") if err != nil { log.Fatal(err) } fmt.Printf("stdout: %s\n", result.Stdout) fmt.Printf("exit_code: %d\n", result.ExitCode) // Write and read a file. if err := sb.Write(ctx, "hello.txt", []byte("Hello, world!")); err != nil { log.Fatal(err) } data, err := sb.Read(ctx, "hello.txt") if err != nil { log.Fatal(err) } fmt.Printf("file content: %s\n", string(data)) } ``` -------------------------------- ### Install Agent Sandbox Extensions Components Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/README.md Installs the agent-sandbox extensions components, which build on the core Sandbox API. Replace 'vX.Y.Z' with a specific version tag. ```bash # Replace "vX.Y.Z" with a specific version tag (e.g., "v0.1.0") from # https://github.com/kubernetes-sigs/agent-sandbox/releases export VERSION="vX.Y.Z" # To install the extensions components: kubectl apply -f https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${VERSION}/extensions.yaml ``` -------------------------------- ### Initialize Agent Sandbox Client and Create Sandbox Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/ray-integration/README.md Initializes the Agent Sandbox client with connection configuration and then creates a sandbox instance, claiming a pre-warmed pod from the specified warm pool using the defined template. ```python # From rl_poc_local.py config = SandboxLocalTunnelConnectionConfig(server_port=8888) self.client = SandboxClient(connection_config=config, cleanup=True) # Claim a hot sandbox from the warm pool instantly self.sandbox = self.client.create_sandbox( template="ray-python-template", warmpool="ray-pool" ) ``` -------------------------------- ### Example HPA Scaling Output Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/hpa-swp-scaling/README.md This is an example of the output you might see when monitoring the HPA scaling. It shows the HPA adjusting replica counts based on the target metric. ```text [2026-04-12 20:49:24] NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE [2026-04-12 20:49:24] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 0/500m 10 100 10 2d23h [2026-04-12 20:52:27] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 250m/500m 10 100 10 2d23h [2026-04-12 20:52:42] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 250m/500m 10 100 16 2d23h [2026-04-12 20:52:58] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 750m/500m 10 100 23 2d23h [2026-04-12 20:53:13] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 750m/500m 10 100 46 2d23h [2026-04-12 20:53:28] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 1/500m 10 100 92 2d23h [2026-04-12 20:53:43] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 1/500m 10 100 100 2d23h [2026-04-12 20:53:58] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 999m/500m 10 100 100 2d23h [2026-04-12 20:54:14] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 999m/500m 10 100 100 2d23h [2026-04-12 20:55:00] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 1/500m 10 100 100 2d23h [2026-04-12 20:55:31] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 999m/500m 10 100 100 2d23h [2026-04-12 20:56:01] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 866m/500m 10 100 100 2d23h [2026-04-12 20:56:31] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 999m/500m 10 100 100 2d23h [2026-04-12 20:57:02] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 1132m/500m 10 100 100 2d23h [2026-04-12 20:57:17] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 1132m/500m 10 100 100 2d23h [2026-04-12 20:57:32] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 982m/500m 10 100 100 2d23h [2026-04-12 20:58:02] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 999m/500m 10 100 100 2d23h [2026-04-12 20:58:33] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 1016m/500m 10 100 100 2d23h [2026-04-12 20:59:03] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 1/500m 10 100 100 2d23h [2026-04-12 21:00:04] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 999m/500m 10 100 100 2d23h [2026-04-12 21:00:34] agent-warmpool-hpa SandboxWarmPool/python-sdk-warmpool 1/500m 10 100 100 2d23h ``` -------------------------------- ### Create Sandbox Client (Direct URL Mode) Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/go/README.md Initialize a new sandbox client using a direct API URL. This bypasses discovery and is useful for internal agents running within the cluster or for connecting via custom domains. Ensure the provided APIURL is correct and accessible. ```go client, err := sandbox.NewClient(ctx, sandbox.Options{ APIURL: "http://sandbox-router-svc.default.svc.cluster.local:8080", }) if err != nil { log.Fatal(err) } defer client.DeleteAll(ctx) sb, err := client.CreateSandbox(ctx, "my-sandbox-template", "default") if err != nil { log.Fatal(err) } entries, err := sb.List(ctx, ".") if err != nil { log.Fatal(err) } fmt.Println(entries) ``` -------------------------------- ### Run Sandbox Client with Tracing via CLI Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/GCP.md Execute the `test_client.py` script with the `--enable-tracing` flag to activate tracing functionality. ```bash python test_client.py --enable-tracing ``` -------------------------------- ### Set up Test Scenario Sandbox Resource Source: https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/policy/kyverno/README.md Applies the Kubernetes resources defined in '.chainsaw-tests/setup-sandbox.yaml' to prepare for testing. ```bash kubectl apply -f .chainsaw-tests/setup-sandbox.yaml ```