CoolFace
Apppublic

vinayakchopra68/code-security-env

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿ›ก๏ธ OpenEnv: Automated Code Security Review

An OpenEnv-compliant, production-grade reinforcement learning environment that simulates a real-world cybersecurity auditing workflow.

๐Ÿ“– Motivation

Historically, reinforcement learning agents have been benchmarked on synthetic arcade games or stateless toy problems. This environment abandons synthetic games to simulate a complex, real-world task: Automated Code Security Review. Agents act as cybersecurity auditors, tasked with analyzing source code, identifying exact vulnerability lines, categorizing threats, and proposing architectural remediations using a strict JSON schema.

๐Ÿง  The Task Curriculum

The environment features a deterministically graded, escalating curriculum consisting of three distinct tasks. The grader provides dense, fractional rewards (0.0 to 1.0) based on partial progress, eliminating the sparse-reward stagnation problem.

  • โ€”Easy (Off-by-One Error): Tests the agent's ability to identify basic array traversal bounds errors.
  • โ€”Medium (Authentication Flaw): Tests the agent's ability to spot logical operator flaws (OR vs AND) that bypass access controls.
  • โ€”Hard (SQL Injection): Tests the agent's ability to detect direct f-string interpolation of unsanitized user inputs into database queries, requiring specific remediation strategies (parameterized queries).

๐Ÿ—„๏ธ State and Action Spaces

This environment strictly adheres to the OpenEnv specification by utilizing Pydantic models for absolute type-safe boundaries.

Action Space (Agent -> Environment)

Agents must submit actions conforming to the following JSON schema:

  • โ€”has_bug (bool): Does a vulnerability exist?
  • โ€”bug_category (str): Enum (SQLi, Auth, Bounds, None).
  • โ€”line_number (int): The exact integer line of the flaw.
  • โ€”severity (str): Enum (critical, high, medium, low, none).
  • โ€”explanation (str): Diagnostic reasoning and remediation instructions.

Observation Space (Environment -> Agent)

Upon stepping, the environment returns:

  • โ€”code_snippet (str): The target source code.
  • โ€”feedback (str): Constructive textual feedback from the deterministic grader.
  • โ€”current_score (float): Accumulated fractional reward (0.0 to 1.0).
  • โ€”is_terminal (bool): True if the agent succeeded or exhausted the step limit.

๐Ÿš€ Setup and Usage Instructions

Option 1: Connect to the Live Hugging Face Space

The environment is securely containerized and hosted live. You can connect your training scripts directly to the cloud instance:

python
# In your inference script
ENV_URL = "https://vinayakchopra68-code-security-env.hf.space"
requests.post(f"{ENV_URL}/reset?difficulty=hard")