mveekshan12/ai-security-openenv
title: AI Security OpenEnv emoji: π colorFrom: red colorTo: blue sdk: docker app_file: app.py pinned: false π AI Security Policy Enforcement & Firewall Optimization (OpenEnv) π Overview This project implements a production-ready OpenEnv environment for evaluating AI agents in cybersecurity workflows. The environment simulates real-world scenarios where an AI agent must detect threats, prevent data leakage, and dynamically generate firewall rules. Built for the Scaler Meta PyTorch Hackathon β OpenEnv track.
π€ HuggingFace Space: mveekshan12/ai-security-openenv π» GitHub: sakshi-kumari28/ai-security-openenv
π Quick Start Prerequisites
Python >= 3.11 Docker HuggingFace account
Installation bashgit clone https://github.com/sakshi-kumari28/ai-security-openenv.git cd ai-security-openenv pip install -r requirements.txt Running Locally bash# Start the Flask server python environment.py bash# Run inference export HFTOKEN=yourtoken export APIBASEURL=https://router.huggingface.co/v1 export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct python inference.py
π Project Structure ai-security-openenv/ βββ environment.py # Flask server + OpenEnv environment βββ inference.py # OpenAI-compatible inference script βββ app.py # App entry point βββ server/ β βββ _init_.py β βββ app.py # Server entry point for multi-mode deployment βββ tasks.py # Task definitions and grading βββ openenv.yaml # OpenEnv specification βββ Dockerfile # Docker configuration βββ requirements.txt # Python dependencies βββ pyproject.toml # Project metadata and scripts βββ uv.lock # Dependency lock file
π― Tasks
- Data Leakage Prevention (Easy)
Event: User attempts to transfer 2GB of data to an external IP Expected Decision: Block the transfer Threat Type: data_exfiltration Response Action: block Max Reward: 1.0
- Threat Detection - Brute Force (Medium)
Event: Multiple failed login attempts followed by a successful login Expected Decision: Block the IP Threat Type: bruteforce Response Action: blockip Max Reward: 1.0
- Advanced Threat Response - Intrusion (Hard)
Event: Unusual data transfer + unknown IP + admin login at 02:30 UTC + sensitive DB query Expected Decision: Block and alert Threat Type: intrusion Response Action: block + alert Firewall Rule: block IP for 24h Max Reward: 1.0
ποΈ Architecture Environment (environment.py)
Flask HTTP server running on port 7860 OpenEnv-compliant API endpoints Deterministic grading engine with partial rewards Seeded randomization for reproducibility
API Endpoints EndpointMethodDescription/GETHealth check β returns 200 OK/healthGETStatus check/resetPOSTReset environment, returns initial state/stepPOSTExecute action, returns observation + reward/stateGETGet current environment state Scoring Weights FieldWeightDescriptionallow0.3Correct allow/block decisionthreattype0.3Correct threat classificationresponseaction0.2Correct response actionfirewall_rule0.2Correct firewall rule (when applicable)
π§ Environment Variables VariableDescriptionExampleAPIBASEURLLLM API endpointhttps://router.huggingface.co/v1MODELNAMEModel identifierQwen/Qwen2.5-72B-InstructHFTOKENHuggingFace API tokenhf_xxx...
π Inference Script The inference script uses the OpenAI client and follows the required stdout format: [START] task=dataleakageprevention env=ai-security-openenv model=Qwen/Qwen2.5-72B-Instruct [STEP] step=1 action={"allow": false, "threattype": "dataexfiltration", "response_action": "block"} reward=0.80 done=true error=null [END] success=true steps=1 score=0.80 rewards=0.80
π Action Schema json{ "allow": false, "threattype": "dataexfiltration", "responseaction": "block", "firewallrule": { "rule_action": "block", "target": "ip", "duration": "24h" } }
π State Schema json{ "eventid": "EVT-001", "logs": ["User initiated data export", "2GB data transfer to external IP"], "userrole": "employee", "data_sensitivity": "high", "status": "open", "decision": null }
π³ Docker bash# Build docker build -t ai-security-openenv .
Run
docker run -p 7860:7860 ai-security-openenv
β OpenEnv Compliance Checklist
β POST /reset endpoint returns valid JSON state β POST /step endpoint accepts action and returns reward β GET /state endpoint returns current state β GET / returns 200 OK for ping check β Deterministic grading with partial rewards β Rewards in range [0.0, 1.0] β 3+ tasks with graders β Docker buildable on port 7860 β inference.py at repo root β inference.py uses OpenAI client β inference.py emits [START]/[STEP]/[END] logs β pyproject.toml with server entry point β uv.lock file present β openenv.yaml specification β Runtime < 20 minutes
π Expected Performance MetricValueSuccess Rateβ₯ 80%Average Rewardβ₯ 0.8Risk LevelLOWConfidenceβ₯ 90%
π Security Scenarios Covered ScenarioDifficultyThreat TypeData Leakage PreventionEasydataexfiltrationBrute Force DetectionMediumbruteforceAdvanced Intrusion ResponseHardintrusion
π License MIT License β see LICENSE for details.
