Skip to main content

A client library to interact with the Lamp Runtime Sandbox on Kubernetes.

Project description

Lamp Runtime Client Python

This Python client provides a simple, high-level interface for creating and interacting with sandboxes managed by the Lamp Runtime Sandbox controller. It's designed to be used as a context manager, ensuring that sandbox resources are properly created and cleaned up.

It supports a scalable, cloud-native architecture using Kubernetes Gateways and a specialized Router, while maintaining a convenient Developer Mode for local testing.

Architecture

The client operates in two modes:

  1. Production (Gateway Mode): Traffic flows from the Client -> Cloud Load Balancer (Gateway) -> Router Service -> Sandbox Pod. This supports high-scale deployments.
  2. Development (Tunnel Mode): Traffic flows from Localhost -> kubectl port-forward -> Router Service -> Sandbox Pod. This requires no public IP and works on Kind/Minikube.
  3. Advanced / Internal Mode: The client connects directly to a provided api_url, bypassing discovery. This is useful for in-cluster communication or when connecting through a custom domain.

Prerequisites

  • A running Kubernetes cluster.
  • The Agent Sandbox Controller installed.
  • kubectl installed and configured locally.

Setup: Deploying the Router

Before using the client, you must deploy the sandbox-router. This is a one-time setup.

  1. Build and Push the Router Image:

    For both Gateway Mode and Tunnel mode, follow the instructions in sandbox-router to build, push, and apply the router image and resources.

  2. Create a Sandbox Template:

    Ensure a SandboxTemplate exists in your target namespace. The test_client.py uses the python-runtime-sandbox image.

    kubectl apply -f python-sandbox-template.yaml
    

Installation

  1. Create a virtual environment:

    python3 -m venv .venv
    source .venv/bin/activate
    
  2. Option 1: Install from source via git:

    # 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"
    
  3. Option 2: Install from source in editable mode:

    If you have not already done so, first clone this repository:

    cd ~
    git clone https://github.com/kubernetes-sigs/agent-sandbox.git
    cd agent-sandbox/clients/python/agentic-sandbox-client
    

    And then install the agentic-sandbox-client into your activated .venv:

    pip install -e .
    

Usage Examples

1. Production Mode (GKE Gateway)

Use this when running against a real cluster with a public Gateway IP. The client automatically discovers the Gateway.

from lamp_runtime import SandboxClient

# Connect via the GKE Gateway
with SandboxClient(
    template_name="python-sandbox-template",
    gateway_name="external-http-gateway",  # Name of the Gateway resource
    namespace="default"
) as sandbox:
    print(sandbox.run("echo 'Hello from Cloud!'").stdout)

2. Developer Mode (Local Tunnel)

Use this for local development or CI. If you omit gateway_name, the client automatically opens a secure tunnel to the Router Service using kubectl.

from lamp_runtime import SandboxClient

# Automatically tunnels to svc/sandbox-router-svc
with SandboxClient(
    template_name="python-sandbox-template",
    namespace="default"
) as sandbox:
    print(sandbox.run("echo 'Hello from Local!'").stdout)

3. Advanced / Internal Mode

Use api_url to bypass discovery entirely. Useful for:

  • Internal Agents: Running inside the cluster (connect via K8s DNS).
  • Custom Domains: Connecting via HTTPS (e.g., https://sandbox.example.com).
with SandboxClient(
    template_name="python-sandbox-template",
    # Connect directly to a URL
    api_url="http://sandbox-router-svc.default.svc.cluster.local:8080",
    namespace="default"
) as sandbox:
    sandbox.run("ls -la")

4. Custom Ports

If your sandbox runtime listens on a port other than 8888 (e.g., a Node.js app on 3000), specify server_port.

with SandboxClient(
    template_name="node-sandbox-template",
    server_port=3000
) as sandbox:
    # ...

Testing

A test script is included to verify the full lifecycle (Creation -> Execution -> File I/O -> Cleanup).

Run in Dev Mode:

python test_client.py --namespace default

Run in Production Mode:

python test_client.py --gateway-name external-http-gateway

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lamp_runtime-0.1.0.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lamp_runtime-0.1.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file lamp_runtime-0.1.0.tar.gz.

File metadata

  • Download URL: lamp_runtime-0.1.0.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for lamp_runtime-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f088ce8ae94dba01334caebe40de33918b5252f3d2732ec1e71d94e714da5d13
MD5 bdc7891c4aa3cf4a4eeedd33f5e815d6
BLAKE2b-256 47d690bf1fe51023f258e506cb8c6bd2388ab89a10f54d4e2e795c18951408c2

See more details on using hashes here.

File details

Details for the file lamp_runtime-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lamp_runtime-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for lamp_runtime-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b72812a3021309e208e147ac60caee846dfc90ba57e7f0f401689ae150e89095
MD5 cd9c9b2cd51dc5b653a04fcd4701d96a
BLAKE2b-256 553d118ef698efc230e19e561a3ca99e6c3596200ae9b28f6d8a1ea32d75e3d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page