You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Initial implementation of Agentic Sandbox Python Client, tester, distribution and packaging files. (#134)
Added build info in README
Added reviewed changes - Implemented logger, readiness probe in the sandbox template, removed unnecessary sleep calls, and updated README for installation instructions.
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.
cd agent-sandbox/clients/agentic-sandbox-client-python
32
+
cd~/path_to_venv
33
+
pip install -e .
34
+
```
35
+
36
+
### Example:
37
+
38
+
```python
39
+
from agentic_sandbox import SandboxClient
40
+
41
+
with SandboxClient(template_name="sandbox-python-template", namespace="default") as sandbox:
42
+
result = sandbox.run("echo 'Hello, World!'")
43
+
print(result.stdout)
44
+
```
45
+
46
+
## How It Works
47
+
48
+
The `SandboxClient` client automates the entire lifecycle of a temporary sandbox environment:
49
+
50
+
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:
51
+
52
+
- **`template_name` (str):** The name of the `SandboxTemplate` resource to use for creating the sandbox.
53
+
- **`namespace` (str, optional):** The Kubernetes namespace to create the `SandboxClaim` in. Defaults to "default".
54
+
- When you create a `SandboxClient` instance within a `with` block, it initiates the process of creating a sandbox.
55
+
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`.
56
+
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.
57
+
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.
58
+
5. **Interaction:** The `SandboxClient` object provides three main methods to interact with the running sandbox:
59
+
*`run(command)`: Executes a shell command inside the sandbox.
60
+
*`write(path, content)`: Uploads a file to the sandbox.
61
+
*`read(path)`: Downloads a file from the sandbox.
62
+
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.
63
+
64
+
65
+
## How to Test the Client
66
+
67
+
A test script, `test_client.py`, is included to verify the client's functionality.
68
+
You should see output indicating that the tests for command execution and file operations have passed.
69
+
70
+
## Packaging and Installation
71
+
72
+
This client is configured as a standard Python package using `pyproject.toml`.
73
+
74
+
### Prerequisites
75
+
76
+
- Python 3.7+
77
+
- `pip`
78
+
- `build` (install with `pip install build`)
79
+
80
+
### Building the Package
81
+
82
+
To build the package from the source, navigate to the `agentic-sandbox-client` directory and run the following command:
83
+
84
+
```bash
85
+
python -m build
86
+
```
87
+
88
+
This will create a `dist` directory containing the packaged distributables: a `.whl` (wheel) file and a `.tar.gz` (source archive).
0 commit comments