Skip to content

Commit 1b32d9f

Browse files
rawwerksclaude
andcommitted
feat: Add env var support to CloudflareREPL
- RLM_CF_WORKER_URL: Default worker URL if not passed - RLM_CF_AUTH_TOKEN: Default auth token if not passed - Updated CLOUDFLARE.md with env var documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f0386a1 commit 1b32d9f

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

‎CLOUDFLARE.md‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,30 @@ First run takes 2-3 minutes to build the container; subsequent runs are faster.
7979

8080
## Using CloudflareREPL
8181

82+
### Environment Variables
83+
84+
CloudflareREPL supports configuration via environment variables:
85+
86+
| Variable | Description |
87+
|----------|-------------|
88+
| `RLM_CF_WORKER_URL` | Default worker URL (if not passed to constructor) |
89+
| `RLM_CF_AUTH_TOKEN` | Default auth token (if not passed to constructor) |
90+
91+
```bash
92+
# Set env vars for easy usage
93+
export RLM_CF_WORKER_URL=https://rlm-sandbox.example.workers.dev
94+
export RLM_CF_AUTH_TOKEN=your-auth-token
95+
```
96+
8297
### Basic Usage
8398

8499
```python
85100
from rlm.environments import get_environment
86101

87-
# Create environment
102+
# With env vars set, minimal config needed:
103+
env = get_environment("cloudflare", {})
104+
105+
# Or explicitly pass URL:
88106
env = get_environment("cloudflare", {
89107
"worker_url": "https://rlm-sandbox.example.workers.dev",
90108
"auth_token": "your-auth-token", # Optional if not configured
@@ -109,12 +127,14 @@ env.cleanup()
109127
```python
110128
from rlm.environments.cloudflare_repl import CloudflareREPL
111129

112-
with CloudflareREPL(
113-
worker_url="https://rlm-sandbox.example.workers.dev",
114-
auth_token="",
115-
) as repl:
130+
# Uses RLM_CF_WORKER_URL and RLM_CF_AUTH_TOKEN env vars
131+
with CloudflareREPL() as repl:
116132
result = repl.execute_code("import numpy as np\nprint(np.sum([1,2,3]))")
117133
print(result.stdout) # "6\n"
134+
135+
# Or with explicit URL
136+
with CloudflareREPL(worker_url="https://rlm-sandbox.example.workers.dev") as repl:
137+
result = repl.execute_code("print('hello')")
118138
```
119139

120140
### Loading Context

‎rlm/environments/cloudflare_repl.py‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import base64
99
import json
10+
import os
1011
import textwrap
1112
import threading
1213
import time
@@ -194,11 +195,15 @@ class CloudflareREPL(IsolatedEnv):
194195
Runs Python code in Cloudflare's container-based Sandbox SDK.
195196
Requires a running Cloudflare Worker with Sandbox SDK configured.
196197
197-
Configuration requires:
198-
- worker_url: URL of the Cloudflare Worker (e.g., https://my-worker.user.workers.dev)
199-
- auth_token: Bearer token for authenticating with the Worker
198+
Configuration:
199+
- worker_url: URL of the Cloudflare Worker (or set RLM_CF_WORKER_URL env var)
200+
- auth_token: Bearer token for the Worker (or set RLM_CF_AUTH_TOKEN env var)
200201
- sandbox_id: Optional sandbox ID for session persistence (auto-generated if not provided)
201202
203+
Environment variables:
204+
- RLM_CF_WORKER_URL: Default worker URL if not passed to constructor
205+
- RLM_CF_AUTH_TOKEN: Default auth token if not passed to constructor
206+
202207
The Worker should expose these endpoints:
203208
- POST /sandbox/exec - Execute a command in the sandbox
204209
- POST /sandbox/write - Write a file to the sandbox
@@ -207,8 +212,8 @@ class CloudflareREPL(IsolatedEnv):
207212

208213
def __init__(
209214
self,
210-
worker_url: str,
211-
auth_token: str,
215+
worker_url: str | None = None,
216+
auth_token: str | None = None,
212217
sandbox_id: str | None = None,
213218
timeout: int = 300,
214219
lm_handler_address: tuple[str, int] | None = None,
@@ -219,8 +224,13 @@ def __init__(
219224
):
220225
super().__init__(**kwargs)
221226

222-
self.worker_url = worker_url.rstrip("/")
223-
self.auth_token = auth_token
227+
# Support env vars for worker URL and auth token
228+
self.worker_url = (worker_url or os.environ.get("RLM_CF_WORKER_URL", "")).rstrip("/")
229+
if not self.worker_url:
230+
raise ValueError(
231+
"worker_url must be provided or RLM_CF_WORKER_URL environment variable must be set"
232+
)
233+
self.auth_token = auth_token if auth_token is not None else os.environ.get("RLM_CF_AUTH_TOKEN", "")
224234
self.sandbox_id = sandbox_id or f"rlm-{int(time.time())}"
225235
self.timeout = timeout
226236
self.lm_handler_address = lm_handler_address

0 commit comments

Comments
 (0)