|
| 1 | +# 16. Self-Hosted Sandbox Agent Demo |
| 2 | + |
| 3 | +This example runs the conversation and model loop in `veadk web`. Each new VeADK Web session creates exactly one remote Managed Session. Only VeADK-generated `agent.tool_use` events are sent to the Self-Hosted Runtime dispatcher, which creates a TAE Tool session for the configured Sandbox. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 🎯 Architecture |
| 8 | + |
| 9 | +```text |
| 10 | + [ User Prompt ] |
| 11 | + │ |
| 12 | + ▼ |
| 13 | + ┌───────────────────────┐ |
| 14 | + │ VeADK Web │ |
| 15 | + │ model + agent loop │ |
| 16 | + └──────────┬────────────┘ |
| 17 | + │ POST agent.tool_use |
| 18 | + ▼ |
| 19 | + ┌───────────────────────────┐ |
| 20 | + │ Runtime 7hw8g3yr │ |
| 21 | + │ dispatcher only │ |
| 22 | + └──────────┬────────────────┘ |
| 23 | + │ creates one tool session |
| 24 | + ▼ |
| 25 | + ┌────────────────────────────────────────┐ |
| 26 | + │ TAE Sandbox Tool m3m24zxs │ |
| 27 | + │ executes the Runtime's tool calls │ |
| 28 | + └────────────────────────────────────────┘ |
| 29 | +``` |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## 🚀 Quick Start |
| 34 | + |
| 35 | +### 1. Configure Environment Variables |
| 36 | + |
| 37 | +Copy the example environment configuration file and update it with your credentials: |
| 38 | + |
| 39 | +```bash |
| 40 | +cp examples/16_self_host_sandbox/.env.example examples/16_self_host_sandbox/.env |
| 41 | +``` |
| 42 | + |
| 43 | +Alternatively, export variables directly: |
| 44 | + |
| 45 | +```bash |
| 46 | +export ANTHROPIC_BASE_URL="https://<runtime-gateway>" |
| 47 | +export ANTHROPIC_ENVIRONMENT_ID="env_01SLqXHseguCmohifEqeUAYu" |
| 48 | +export ANTHROPIC_ENVIRONMENT_KEY="your-runtime-token" |
| 49 | +export SANDBOX_AGENT_ID="agent_your_managed_agent_id" |
| 50 | +export X_TOP_ACCOUNT_ID="your-account-id" |
| 51 | +``` |
| 52 | + |
| 53 | +The local VeADK process needs its normal model configuration. Model reasoning happens in VeADK; only tool execution is delegated to the remote Runtime and Sandbox. |
| 54 | + |
| 55 | + |
| 56 | +### 2. Run the Demo |
| 57 | + |
| 58 | +#### Option A: Web UI Mode (`veadk web`) |
| 59 | + |
| 60 | +Run the visual web debugging interface in your browser (defaults to port **8067**, configurable via `PORT` in `.env` or `--port`): |
| 61 | + |
| 62 | +```bash |
| 63 | +# Via run.sh helper (automatically switches to agents dir and applies port 8067) |
| 64 | +bash examples/16_self_host_sandbox/run.sh --web |
| 65 | + |
| 66 | +# Or directly in the agents directory |
| 67 | +cd examples/16_self_host_sandbox/agents |
| 68 | +veadk web --port 8067 |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +#### Option B: CLI Mode |
| 75 | + |
| 76 | +```bash |
| 77 | +# Run with run.sh helper |
| 78 | +bash examples/16_self_host_sandbox/run.sh |
| 79 | + |
| 80 | +# Or using uv |
| 81 | +uv run --extra sandbox python examples/16_self_host_sandbox/main.py |
| 82 | + |
| 83 | +# Or select an existing local-to-remote session mapping |
| 84 | +python examples/16_self_host_sandbox/main.py \ |
| 85 | + --session-id "my-local-session" \ |
| 86 | + --prompt "Create a Python script in /workspace and run it with pytest." |
| 87 | +``` |
| 88 | + |
| 89 | + |
| 90 | +`ShortTermMemory.after_create_session_callback` creates one remote Managed Session |
| 91 | +for each newly created VeADK session. VeADK handles the user message and model |
| 92 | +loop locally. `DispatchRuntimeProvider` intercepts each model tool call, posts an |
| 93 | +`agent.tool_use`, waits for its matching tool result, and returns that result to |
| 94 | +the local VeADK model loop. |
| 95 | + |
| 96 | +## Docker and Kubernetes deployment |
| 97 | + |
| 98 | +Use the repository root as the Docker build context: |
| 99 | + |
| 100 | +```bash |
| 101 | +docker build \ |
| 102 | + -f examples/16_self_host_sandbox/Dockerfile \ |
| 103 | + -t <registry>/veadk-self-host-sandbox:<tag> \ |
| 104 | + . |
| 105 | +docker push <registry>/veadk-self-host-sandbox:<tag> |
| 106 | +``` |
| 107 | + |
| 108 | +Replace the image and Ingress host in `k8s.yaml` for the target environment. Then |
| 109 | +create an allowlisted Secret from the local `.env` and deploy the workload: |
| 110 | + |
| 111 | +```bash |
| 112 | +set -a |
| 113 | +source examples/16_self_host_sandbox/.env |
| 114 | +set +a |
| 115 | + |
| 116 | +kubectl create secret generic veadk-self-host-sandbox-env \ |
| 117 | + --from-literal=ANTHROPIC_BASE_URL="$ANTHROPIC_BASE_URL" \ |
| 118 | + --from-literal=ANTHROPIC_ENVIRONMENT_ID="$ANTHROPIC_ENVIRONMENT_ID" \ |
| 119 | + --from-literal=ANTHROPIC_ENVIRONMENT_KEY="$ANTHROPIC_ENVIRONMENT_KEY" \ |
| 120 | + --from-literal=SANDBOX_AGENT_ID="$SANDBOX_AGENT_ID" \ |
| 121 | + --from-literal=X_TOP_ACCOUNT_ID="$X_TOP_ACCOUNT_ID" \ |
| 122 | + --dry-run=client -o yaml | kubectl apply -f - |
| 123 | + |
| 124 | +kubectl apply -f examples/16_self_host_sandbox/k8s.yaml |
| 125 | +kubectl rollout status deployment/veadk-self-host-sandbox |
| 126 | +``` |
| 127 | + |
| 128 | +Do not create the Secret from the entire `.env`. The Deployment only injects |
| 129 | +the allowlisted Runtime connection values above. |
| 130 | + |
| 131 | +## Development verification |
| 132 | + |
| 133 | +The repository virtual environment may omit test dependencies when it was |
| 134 | +created for runtime use only. Install the development dependency group before |
| 135 | +running the focused dispatch tests: |
| 136 | + |
| 137 | +```bash |
| 138 | +uv sync --group dev --extra sandbox |
| 139 | +uv run pytest -q tests/runtime/test_self_host_sandbox_client.py \ |
| 140 | + tests/runtime/test_self_host_sandbox_agent.py |
| 141 | +``` |
0 commit comments