File size: 12,776 Bytes
344db23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# Tech Stack β€” What's Mandatory vs Optional

---

## What Each Sponsor Actually Provides

| Sponsor | Role | What They Give You |
|---------|------|--------------------|
| **Meta** | Primary Sponsor | The **OpenEnv framework** (openenv-core). The whole concept. Judging. Interview access. |
| **HuggingFace** | Ecosystem Partner | **HF Spaces** (deployment platform). Environment Hub. `HF_TOKEN` for auth. Model hosting. |
| **PyTorch** | Framework Partner | The ML training framework. Used for **Round 2 / RL training** β€” NOT for building the environment in Round 1. |
| **Scaler SST** | Powered By | Event organizer. Round 2 venue in Bangalore. |

---

## MANDATORY Tech (You MUST use these)

### 1. openenv-core (>= 0.2.2)

**What it is:** The core framework by Meta. This IS the hackathon.

**What it provides:**
```
Base classes:
  - Action (Pydantic BaseModel)        ← your action type extends this
  - Observation (Pydantic BaseModel)    ← your observation type extends this
  - State (Pydantic BaseModel)          ← your state type extends this
  - Environment (ABC)                   ← your env logic extends this
  - EnvClient (ABC)                     ← your client extends this

Server factory:
  - create_app() / create_fastapi_app() ← generates all endpoints automatically

CLI tools:
  - openenv validate                    ← validates your submission
  - openenv push                        ← deploys to HF Spaces

Rubric system:
  - Rubric, Sequential, WeightedSum     ← reward computation
  - TrajectoryRubric                    ← episode-level rewards

WebSocket server:
  - Handles /ws, /reset, /step, /state, /health, /schema, /docs
```

**Install:** `pip install openenv-core`

### 2. FastAPI (>= 0.104.0)

**What it is:** Web framework. openenv-core uses it internally.

**Why mandatory:** `create_app()` returns a FastAPI application. Your server IS a FastAPI app.

**You don't write FastAPI routes manually** β€” `create_app()` does it for you. But if you need custom endpoints (`/tasks`, `/grader`, `/baseline`), you add them to the FastAPI app.

### 3. Uvicorn (>= 0.24.0)

**What it is:** ASGI server that runs FastAPI.

**Why mandatory:** Your Dockerfile's CMD is `uvicorn server.app:app --host 0.0.0.0 --port 8000`

### 4. Pydantic (>= 2.0.0)

**What it is:** Data validation. Like Zod for Python.

**Why mandatory:** Action, Observation, State are all Pydantic BaseModels. Your typed models MUST extend them.

### 5. Docker

**What it is:** Containerization. You already know this.

**Why mandatory:** Problem statement says "Must include a working Dockerfile. docker build + docker run must work."

### 6. HuggingFace Spaces

**What it is:** Like Vercel but for ML apps. Hosts your container.

**Why mandatory:** "Deploys to a Hugging Face Space tagged with openenv." Your running environment lives here.

**Deploy:** Either `openenv push --repo-id yourname/your-env` or manually create a Space.

### 7. OpenAI Python Client

**What it is:** The `openai` pip package.

**Why mandatory:** Problem statement says "Participants must use OpenAI Client for all LLM calls."

**Important:** You're NOT calling OpenAI's API. You're using the OpenAI CLIENT LIBRARY to call whatever model is at `API_BASE_URL`. It's an OpenAI-compatible endpoint (could be HuggingFace, could be anything).

```python
from openai import OpenAI

client = OpenAI(
    base_url=os.environ["API_BASE_URL"],  # NOT openai.com β€” it's the judges' endpoint
    api_key=os.environ["HF_TOKEN"],        # NOT OPENAI_API_KEY
)

completion = client.chat.completions.create(
    model=os.environ["MODEL_NAME"],  # e.g., "nvidia/Nemotron-3-Super"
    messages=[...],
)
```

### 8. Python >= 3.10

**Why:** openenv-core requires it. Use 3.11 (same as reference projects).

---

## NOT Mandatory (Despite Being Sponsors)

### PyTorch β€” NOT NEEDED for Round 1

PyTorch is the "Framework Partner" because it's used for **RL training** (Round 2, Module 5 of course, GRPO with TRL).

But Round 1 is about **building the environment** β€” the thing the AI plays in. The environment is a FastAPI server. No neural networks, no training, no GPU.

**None of the 5 SF winning environments import PyTorch:**
- Calendar env: No PyTorch
- REPL env: No PyTorch
- TB2 env: No PyTorch
- Reasoning Gym: No PyTorch
- CARLA env: Uses it optionally, not required

**DO NOT add PyTorch to your requirements.** It will blow your 8GB RAM limit.

### Transformers / TRL β€” NOT NEEDED

Same reason. These are for training. Your env doesn't train anything.

### LangChain β€” NOT NEEDED

Calendar env uses it for multi-provider LLM support in their client. But the problem statement says use OpenAI client. Don't add LangChain complexity.

---

## RECOMMENDED Tech (Used by Winners, Good to Use)

### SQLAlchemy + SQLite β€” STRONGLY RECOMMENDED

**Used by:** Calendar env (the likely top winner)

**Why:** Gives you real database state. Graders can run SQL queries to verify agent's work. Way more professional than Python dicts.

For our security audit env:
```python
# Tables:
# hosts, ports, services, vulnerabilities (ground truth β€” static)
# agent_discoveries, agent_findings (agent's work β€” grows during episode)
# Grader: SELECT COUNT(*) FROM vulnerabilities v
#          JOIN agent_findings f ON v.id = f.finding_vuln_id
```

### websockets β€” RECOMMENDED

openenv-core uses it internally. May need to add explicitly.

### httpx β€” OPTIONAL

Better HTTP client than requests. Used by Calendar env.

### pytest β€” OPTIONAL

Useful for testing your env locally before submission. TB2 uses it for grading.

---

## Your Exact requirements.txt

```
# Core (MANDATORY)
openenv-core>=0.2.2
fastapi>=0.110.0
uvicorn[standard]>=0.27.0
pydantic>=2.5.0
websockets

# Database (RECOMMENDED β€” like Calendar env winner)
sqlalchemy>=2.0.0

# Inference script (MANDATORY)
openai>=1.0.0

# Utilities
python-dotenv>=1.0.0
requests>=2.31.0
```

**Total size: < 50MB installed. Runs easily on vcpu=2, 8GB.**

Compare to what you'd have with PyTorch: 2GB+ installed, would crash on 8GB.

---

## Your Exact openenv.yaml

```yaml
spec_version: 1
name: security_audit_env
type: space
runtime: fastapi
app: server.app:app
port: 8000
```

That's it. 6 lines. Same format as every SF winner.

---

## Your Exact Dockerfile

```dockerfile
FROM python:3.11-slim

WORKDIR /app

# System deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl gcc && rm -rf /var/lib/apt/lists/*

# Python deps
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# App code
COPY . .

# Health check
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
    CMD curl -f http://localhost:8000/health || exit 1

EXPOSE 8000

CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
```

---

## Your Exact inference.py Header

```python
#!/usr/bin/env python3
"""Security Audit Environment β€” Baseline Inference Script"""

import os
from openai import OpenAI

# MANDATORY env vars β€” exact names from dashboard
API_BASE_URL = os.environ["API_BASE_URL"]
MODEL_NAME = os.environ["MODEL_NAME"]
HF_TOKEN = os.environ["HF_TOKEN"]

# OpenAI client pointing at the judges' endpoint (NOT openai.com)
client = OpenAI(base_url=API_BASE_URL, api_key=HF_TOKEN)

# Your environment client
from security_audit_env import SecurityAuditEnv, SecurityAuditAction

SYSTEM_PROMPT = """You are a professional security auditor..."""

MAX_STEPS = 30  # Must finish in < 20 minutes
TEMPERATURE = 0.0  # Reproducible scores
MAX_TOKENS = 1024
```

---

## Architecture Diagram β€” What Connects to What

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              HuggingFace Spaces                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚     Your Docker Container                  β”‚  β”‚
β”‚  β”‚                                            β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚ FastAPI App   β”‚    β”‚  SQLite DB      β”‚  β”‚  β”‚
β”‚  β”‚  β”‚ (openenv-core)│◄──►│  (network state)β”‚  β”‚  β”‚
β”‚  β”‚  β”‚               β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”‚ Endpoints:    β”‚                         β”‚  β”‚
β”‚  β”‚  β”‚  /reset       β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚  /step        β”‚    β”‚ SecurityAudit   β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  /state       │◄──►│ Environment     β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  /health      β”‚    β”‚ (your logic)    β”‚  β”‚  β”‚
β”‚  β”‚  β”‚  /ws          β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β”‚  /tasks       β”‚                         β”‚  β”‚
β”‚  β”‚  β”‚  /grader      β”‚                         β”‚  β”‚
β”‚  β”‚  β”‚  /baseline    β”‚                         β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                          β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                     β–²                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚ WebSocket / HTTP
                      β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  inference.py       β”‚                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚  β”‚  OpenAI Client                    β”‚            β”‚
β”‚  β”‚  (calls your env via WebSocket)   β”‚            β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β”‚                     β”‚                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚  β”‚  LLM (Nemotron / GPT / etc)      β”‚            β”‚
β”‚  β”‚  at API_BASE_URL                  β”‚            β”‚
β”‚  β”‚  (judges provide this)            β”‚            β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## Quick Start: Scaffold with `openenv init`

```bash
pip install openenv-core
openenv init security_audit_env
```

This generates the entire project structure automatically:
```
security_audit_env/
β”œβ”€β”€ __init__.py          # Package exports
β”œβ”€β”€ models.py            # Action, Observation, State (edit these)
β”œβ”€β”€ client.py            # EnvClient (edit these)
β”œβ”€β”€ openenv.yaml         # Manifest (already configured)
β”œβ”€β”€ pyproject.toml       # Dependencies (add yours)
β”œβ”€β”€ inference.py         # Baseline script (WRITE THIS β€” mandatory for hackathon)
β”œβ”€β”€ README.md            # Documentation
└── server/
    β”œβ”€β”€ __init__.py
    β”œβ”€β”€ environment.py   # Your env logic β€” reset/step/state (MAIN FILE)
    β”œβ”€β”€ app.py           # FastAPI app (already wired)
    β”œβ”€β”€ requirements.txt # Server deps
    └── Dockerfile       # Container spec
```

Then customize: `models.py` β†’ `server/environment.py` β†’ `client.py` β†’ `inference.py`

Deploy: `openenv push --repo-id yourname/security-audit-env`

Validate: `openenv validate .` (local) or `openenv validate --url https://your-space.hf.space` (remote)

---

## Summary: What You're Actually Building

```
You build:
  1. A FastAPI server (using openenv-core) ← the "environment"
  2. A SQLite database ← the simulated network state
  3. A Dockerfile ← containerization
  4. An inference.py ← baseline agent using OpenAI client
  5. Deploy to HF Spaces ← hosting

You DO NOT build:
  βœ— Any ML model
  βœ— Any PyTorch code
  βœ— Any training pipeline
  βœ— Any neural network
  βœ— Any GPU code

Your tech stack is essentially:
  Python + FastAPI + SQLite + Docker + HuggingFace Spaces
  (Plus openenv-core for the framework glue)

This is a full-stack web project. You already know 90% of this.
```