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
Copy file name to clipboardExpand all lines: examples/sandboxed-tools/README.md
+59-22Lines changed: 59 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,54 +7,91 @@ By keeping the sandbox lifetime scoped strictly to the duration of a tool call,
7
7
## Architecture & Key Concepts
8
8
9
9
1.**Minimal OpenAI-Compatible Client (`pkg/llm`)**: A lightweight Go client built on `net/http` without a third-party OpenAI SDK that interacts with OpenAI-compatible API endpoints (such as the Gemini API via its OpenAI compatibility layer). It supports function calling (tools) and tool call responses.
10
-
2.**Ephemeral Sandbox Execution**: When the LLM requests a tool call (e.g., `run_command`), the application provisions a temporary sandbox directly using the low-level `agentsclientset`, executes the requested command via the Pod "exec" API, and immediately deletes the `Sandbox` resource.
10
+
2.**Ephemeral Sandbox Execution**: When the LLM requests a tool call, the application provisions a temporary sandbox directly using the low-level `agentsclientset`, executes the requested tool, and immediately deletes the `Sandbox` resource once execution completes.
11
+
3.**Session Persistence via Snapshots**: To maintain continuity across different turns of a conversation, the application automatically snapshots the sandbox's home directory (`/home/clawtainer` by default) before deleting the sandbox.
12
+
- These snapshots are saved as local tarball files on the host machine under `~/.local/sandboxed-tools/<session>/fs/backup-*.tar.gz`.
13
+
- When a new tool call is made, the application creates a fresh sandbox and automatically restores the latest snapshot into `/home/clawtainer` before executing the tool.
14
+
- Only the last 5 backups are retained per session; older backups are automatically pruned.
15
+
16
+
## Command-Line Arguments (CLI Options)
17
+
18
+
The application accepts the following command-line flags:
19
+
20
+
| Flag | Description | Default / Fallback |
21
+
| :--- | :--- | :--- |
22
+
|`-session`|**Required**. A unique alphanumeric name (max 40 characters) to identify this agent session and store/restore its filesystem snapshots. | None |
23
+
|`-namespace`| The Kubernetes namespace where sandbox pods are created. |`default` (overrides `SANDBOX_NAMESPACE` env var) |
24
+
|`-image`| The container image used for the temporary sandbox pod. |`debian:bookworm-slim` (overrides `SANDBOX_IMAGE` env var) |
25
+
|`-homedir`| The directory inside the sandbox that is persisted via snapshot/restore. |`/home/clawtainer` (overrides `SANDBOX_HOME_DIR` env var) |
11
26
12
27
## Configuration
13
28
14
-
The application is configured via environment variables:
29
+
The application is configured via environment variables (usually for API keys and endpoint configuration):
15
30
16
-
| Variable | Description | Default |
31
+
| Variable | Description | Default / Fallback |
17
32
| :--- | :--- | :--- |
18
33
|`GEMINI_API_KEY`| Your Gemini API key (or `OPENAI_API_KEY`). |**Required**|
19
34
|`OPENAI_BASE_URL`| The base URL for the OpenAI-compatible API. |`https://generativelanguage.googleapis.com/v1beta/openai`|
20
35
|`OPENAI_MODEL`| The model name to use for chat completions (or `MODEL`). |`gemini-3.5-flash`|
21
-
|`SANDBOX_IMAGE`| The container image used for the temporary sandbox pod. |`debian:bookworm-slim`|
22
-
|`SANDBOX_NAMESPACE`| The Kubernetes namespace where sandboxes are created. |`default`|
36
+
|`SANDBOX_IMAGE`| Fallback container image if `-image` flag is not set. |`debian:bookworm-slim`|
37
+
|`SANDBOX_NAMESPACE`| Fallback Kubernetes namespace if `-namespace` flag is not set. |`default`|
38
+
|`SANDBOX_HOME_DIR`| Fallback persisted directory if `-homedir` flag is not set. |`/home/clawtainer`|
39
+
40
+
## Available Tools
41
+
42
+
The LLM has access to a powerful suite of tools configured in the registry (`pkg/tools`):
43
+
44
+
***`run_command`**: Executes an arbitrary shell command inside the sandbox container, returning `stdout`, `stderr`, and the `exit_code`.
45
+
***`ls`**: Lists the files and directories inside a specific folder (defaults to the current directory).
46
+
***`read`**: Reads the full contents of a file from the sandbox.
47
+
***`write`**: Writes specified content to a file, automatically creating parent directories if they do not exist and overwriting the file if it does.
23
48
24
49
## Running the Example
25
50
51
+
Make sure your Kubernetes cluster is running and accessible via your active `kubeconfig` context.
52
+
26
53
```bash
27
54
# Set your API key
28
55
export GEMINI_API_KEY="your-api-key-here"
29
56
30
-
# Run the chat interface
31
-
go run ./examples/sandboxed-tools/main.go
57
+
# Run the chat interface, specifying a session name
58
+
go run ./examples/sandboxed-tools/main.go -session myfirstsession
I0530 12:00:05.125000 12345 write_file.go:67] creating directory in sandbox dir="/home/clawtainer"
80
+
I0530 12:00:05.500000 12345 write_file.go:75] writing file in sandbox path="/home/clawtainer/greeting.txt"
81
+
I0530 12:00:06.123456 12345 main.go:790] snapshotting filesystem from sandbox... sandbox.name="sandbox-tool-abcde"
82
+
I0530 12:00:06.200000 12345 main.go:445] saved filesystem state to new backup backup="/home/user/.local/sandboxed-tools/myfirstsession/fs/backup-20260530T120006.tar.gz"
I0530 12:00:11.306000 12345 list_files.go:56] listing files in sandbox path="/home/clawtainer"
90
+
I0530 12:00:12.100000 12345 main.go:790] snapshotting filesystem from sandbox... sandbox.name="sandbox-tool-fghij"
91
+
I0530 12:00:12.150000 12345 main.go:445] saved filesystem state to new backup backup="/home/user/.local/sandboxed-tools/myfirstsession/fs/backup-20260530T120012.tar.gz"
0 commit comments