Skip to content

Commit 1b20ba3

Browse files
committed
Merge remote-tracking branch 'upstream' into AddNetworkPolicy
2 parents 4f60f49 + ba768e6 commit 1b20ba3

36 files changed

+1110
-14
lines changed

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.PHONY: all
2-
all: fix-go-generate build lint-go test-unit
2+
all: fix-go-generate build lint-go test-unit toc-verify
33

44
.PHONY: fix-go-generate
55
fix-go-generate:
@@ -32,3 +32,18 @@ test-e2e:
3232
.PHONY: lint-go
3333
lint-go:
3434
./dev/tools/lint-go
35+
36+
# Example usage: make release TAG=v0.1.0
37+
.PHONY: release
38+
release:
39+
go mod tidy
40+
go generate ./...
41+
./dev/tools/release --tag=${TAG}
42+
43+
.PHONY: toc-update
44+
toc-update:
45+
./dev/tools/update-toc
46+
47+
.PHONY: toc-verify
48+
toc-verify:
49+
./dev/tools/verify-toc

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,63 @@
44

55
This project is developing a `Sandbox` Custom Resource Definition (CRD) and controller for Kubernetes, under the umbrella of [SIG Apps](https://github.com/kubernetes/community/tree/master/sig-apps). The goal is to provide a declarative, standardized API for managing workloads that require the characteristics of a long-running, stateful, singleton container with a stable identity, much like a lightweight, single-container VM experience built on Kubernetes primitives.
66

7+
## Overview
8+
9+
### Core: Sandbox
10+
11+
The `Sandbox` CRD is the core of agent-sandbox. It provides a declarative API for managing a single, stateful pod with a stable identity and persistent storage. This is useful for workloads that don't fit well into the stateless, replicated model of Deployments or the numbered, stable model of StatefulSets.
12+
13+
Key features of the `Sandbox` CRD include:
14+
15+
* **Stable Identity:** Each Sandbox has a stable hostname and network identity.
16+
* **Persistent Storage:** Sandboxes can be configured with persistent storage that survives restarts.
17+
* **Lifecycle Management:** The Sandbox controller manages the lifecycle of the pod, including creation, scheduled deletion, pausing and resuming.
18+
19+
### Extensions
20+
21+
The `extensions` module provides additional CRDs and controllers that build on the core `Sandbox` API to provide more advanced features.
22+
23+
* `SandboxTemplate`: Provides a way to define reusable templates for creating Sandboxes, making it easier to manage large numbers of similar Sandboxes.
24+
* `SandboxClaim`: Allows users to create Sandboxes from a template, abstracting away the details of the underlying Sandbox configuration.
25+
* `SandboxWarmPool`: Manages a pool of pre-warmed Sandbox Pods that can be quickly allocated to users, reducing the time it takes to get a new Sandbox up and running.
26+
27+
## Installation
28+
29+
You can install the agent-sandbox controller and its CRDs with the following command.
30+
31+
```sh
32+
# Replace "vX.Y.Z" with a specific version tag (e.g., "v0.1.0") from
33+
# https://github.com/kubernetes-sigs/agent-sandbox/releases
34+
export VERSION="vX.Y.Z"
35+
36+
# To install only the core components:
37+
kubectl apply -f https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${VERSION}/manifest.yaml
38+
39+
# To install the extensions components:
40+
kubectl apply -f https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${VERSION}/extensions.yaml
41+
```
42+
43+
## Getting Started
44+
45+
Once you have installed the controller, you can create a simple Sandbox by applying the following YAML to your cluster:
46+
47+
```yaml
48+
apiVersion: agents.x-k8s.io/v1alpha1
49+
kind: Sandbox
50+
metadata:
51+
name: my-sandbox
52+
spec:
53+
template:
54+
spec:
55+
containers:
56+
- name: my-container
57+
image: <IMAGE>
58+
```
59+
60+
This will create a new Sandbox named `my-sandbox` running the image you specify. You can then access the Sandbox using its stable hostname, `my-sandbox`.
61+
62+
For more complex examples, including how to use the extensions, please see the [examples/](examples/) and [extensions/examples/](extensions/examples/) directories.
63+
764
## Motivation
865

966
Kubernetes excels at managing stateless, replicated applications (Deployments) and stable, numbered sets of stateful pods (StatefulSets). However, there's a growing need for an abstraction to handle use cases such as:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
build/
2+
venv/
3+
4+
__pycache__/
5+
*.pyc
6+
.env
7+
.DS_Store
8+
.idea/
9+
.vscode/
10+
logs/
11+
*.log
12+
13+
agentic_sandbox.egg-info/
14+
dist/
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Agentic Sandbox Client Python
2+
3+
This Python client provides a simple, high-level interface for creating and interacting with sandboxes managed by the Agent Sandbox controller. It's designed to be used as a context manager, ensuring that sandbox resources are properly created and cleaned up.
4+
5+
## Usage
6+
7+
### Prerequisites
8+
9+
- A running Kubernetes cluster (e.g., `kind`).
10+
- The Agent Sandbox controller must be deployed with the extensions feature enabled.
11+
- A `SandboxTemplate` resource must be created in the cluster.
12+
- The `kubectl` command-line tool must be installed and configured to connect to your cluster.
13+
14+
### Installation
15+
16+
1. **Create a virtual environment:**
17+
```bash
18+
python3 -m venv .venv
19+
```
20+
2. **Activate the virtual environment:**
21+
```bash
22+
source .venv/bin/activate
23+
```
24+
3. **Option 1: Install from source via git:**
25+
```bash
26+
# Replace "main" with a specific version tag (e.g., "v0.1.0") from
27+
# https://github.com/kubernetes-sigs/agent-sandbox/releases to pin a version tag.
28+
export VERSION="main"
29+
30+
pip install "git+https://github.com/kubernetes-sigs/agent-sandbox.git@${VERSION}#subdirectory=clients/python/agentic-sandbox-client"
31+
```
32+
4. **Option 2: Install from source in editable mode:**
33+
```bash
34+
git clone https://github.com/kubernetes-sigs/agent-sandbox.git
35+
cd agent-sandbox/clients/agentic-sandbox-client-python
36+
cd ~/path_to_venv
37+
pip install -e .
38+
```
39+
40+
### Example:
41+
42+
```python
43+
from agentic_sandbox import SandboxClient
44+
45+
with SandboxClient(template_name="sandbox-python-template", namespace="default") as sandbox:
46+
result = sandbox.run("echo 'Hello, World!'")
47+
print(result.stdout)
48+
```
49+
50+
## How It Works
51+
52+
The `SandboxClient` client automates the entire lifecycle of a temporary sandbox environment:
53+
54+
1. **Initialization (`with SandboxClient(...)`):** The client is initialized with the name of the `SandboxTemplate` you want to use and the namespace where the resources should be created:
55+
56+
- **`template_name` (str):** The name of the `SandboxTemplate` resource to use for creating the sandbox.
57+
- **`namespace` (str, optional):** The Kubernetes namespace to create the `SandboxClaim` in. Defaults to "default".
58+
- When you create a `SandboxClient` instance within a `with` block, it initiates the process of creating a sandbox.
59+
2. **Claim Creation:** It creates a `SandboxClaim` Kubernetes resource. This claim tells the agent-sandbox controller to provision a new sandbox using a predefined `SandboxTemplate`.
60+
3. **Waiting for Readiness:** The client watches the Kubernetes API for the corresponding `Sandbox` resource to be created and become "Ready". This indicates that the pod is running and the server inside is active.
61+
4. **Port Forwarding:** Once the sandbox pod is ready, the client automatically starts a `kubectl port-forward` process in the background. This creates a secure tunnel from your local machine to the sandbox pod, allowing you to communicate with the server running inside.
62+
5. **Interaction:** The `SandboxClient` object provides three main methods to interact with the running sandbox:
63+
* `run(command)`: Executes a shell command inside the sandbox.
64+
* `write(path, content)`: Uploads a file to the sandbox.
65+
* `read(path)`: Downloads a file from the sandbox.
66+
6. **Cleanup (`__exit__`):** When the `with` block is exited (either normally or due to an error), the client automatically cleans up all resources. It terminates the `kubectl port-forward` process and deletes the `SandboxClaim`, which in turn causes the controller to delete the `Sandbox` pod.
67+
68+
69+
## How to Test the Client
70+
71+
A test script, `test_client.py`, is included to verify the client's functionality.
72+
You should see output indicating that the tests for command execution and file operations have passed.
73+
74+
## Packaging and Installation
75+
76+
This client is configured as a standard Python package using `pyproject.toml`.
77+
78+
### Prerequisites
79+
80+
- Python 3.7+
81+
- `pip`
82+
- `build` (install with `pip install build`)
83+
84+
### Building the Package
85+
86+
To build the package from the source, navigate to the `agentic-sandbox-client` directory and run the following command:
87+
88+
```bash
89+
python -m build
90+
```
91+
92+
This will create a `dist` directory containing the packaged distributables: a `.whl` (wheel) file and a `.tar.gz` (source archive).
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2025 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from .sandbox_client import SandboxClient

0 commit comments

Comments
 (0)