--- title: Code Security Review OpenEnv emoji: 🛡️ colorFrom: gray colorTo: purple sdk: docker pinned: false tags: - openenv --- # Code Security Review — OpenEnv Environment An RL environment for training AI agents to perform real-world code security review. Agents analyze code from production pull requests across a **two-phase** multi-step workflow: first discovering the hidden file, then identifying the vulnerability. Built by **Inmodel Labs** for the Meta PyTorch OpenEnv Hackathon. --- ## Environment Overview | Field | Value | |---|---| | Tasks | 3 (easy → medium → hard) | | Languages | Python, JavaScript | | Action space | Phase 1: `{"request_file": true}` / Phase 2: Structured JSON (6 fields) | | Reward range | 0.0 – 1.0 (clamped) | | Steps per episode | 2 (max) | --- ## Tasks | ID | Language | Bug Class | Difficulty | |---|---|---|---| | `python-off-by-one` | Python | Off-by-one index error | Easy | | `js-idor-auth` | JavaScript | Insecure Direct Object Reference (IDOR) | Medium | | `python-pickle-deserialization` | Python | Insecure Deserialization (RCE) | Hard | --- ## Two-Phase Episode Walkthrough The agent operates in a **2-step sequential workflow** that mirrors a real AppSec triage process: **Step 1 — File Discovery** (`+0.20`) The agent receives only the PR title and file path. The code is hidden. The agent must request access: ```json {"request_file": true} ``` The environment unlocks the code snippet and returns it in the observation. **Step 2 — Security Review** (up to `+0.80`) The agent analyses the code and submits a structured JSON finding: ```json { "bug_identified": true, "bug_location": "line 3 — range(len(transactions) + 1)", "bug_type": "off-by-one", "bug_description": "Off-by-one error causes IndexError on last iteration...", "severity": "medium", "suggested_fix": "Change range(len(transactions) + 1) to range(len(transactions))" } ``` --- ## Action Space ### Phase 1 — File Request ```json {"request_file": true} ``` ### Phase 2 — Bug Review | Field | Type | Values | |---|---|---| | `bug_identified` | bool | `true` / `false` | | `bug_location` | string | location description | | `bug_type` | string | `off-by-one` \| `logic-error` \| `insecure-deserialization` \| `none` | | `bug_description` | string | detailed vulnerability explanation | | `severity` | string | `none` \| `low` \| `medium` \| `high` \| `critical` | | `suggested_fix` | string | how to fix the bug | ## Observation Space ```json { "task_id": "python-pickle-deserialization", "language": "Python", "difficulty": "hard", "code_snippet": "