codefix-env 0.2.1__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codefix_env-0.2.1/src/codefix_env.egg-info → codefix_env-0.2.3}/PKG-INFO +139 -299
- codefix_env-0.2.3/README.md +236 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/pyproject.toml +1 -1
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/__init__.py +1 -1
- {codefix_env-0.2.1 → codefix_env-0.2.3/src/codefix_env.egg-info}/PKG-INFO +139 -299
- codefix_env-0.2.1/README.md +0 -396
- {codefix_env-0.2.1 → codefix_env-0.2.3}/LICENSE +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/MANIFEST.in +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/SECURITY.md +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/setup.cfg +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/cli.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/client.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/env.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/models.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/rewards.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/tasks/__init__.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/tasks/easy.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/tasks/hard.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/tasks/medium.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/utils/__init__.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/utils/metrics.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/utils/reward_model.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env/utils/sandbox.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env.egg-info/SOURCES.txt +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env.egg-info/dependency_links.txt +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env.egg-info/entry_points.txt +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env.egg-info/requires.txt +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/src/codefix_env.egg-info/top_level.txt +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/tests/test_env.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/tests/test_rewards.py +0 -0
- {codefix_env-0.2.1 → codefix_env-0.2.3}/tests/test_tasks.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codefix-env
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: A high-performance PyTorch-based RL environment for automated code debugging and LLM agent evaluation
|
|
5
5
|
Author-email: Shailendra Dhakad <dhakarshailendra829@gmail.com>
|
|
6
6
|
License: Apache License
|
|
@@ -267,244 +267,107 @@ Dynamic: license-file
|
|
|
267
267
|
|
|
268
268
|
<div align="center">
|
|
269
269
|
|
|
270
|
-
# CodeFix-Env
|
|
271
|
-
|
|
272
|
-
**A reinforcement learning environment for training LLM-driven agents to autonomously debug, localize, and repair code through sandboxed execution and feedback-driven learning.**
|
|
273
|
-
|
|
274
270
|
<p align="center">
|
|
275
|
-
<
|
|
271
|
+
<img src="docs/logo/codefix_logo.png" alt="CodeFix-Env" width="360" />
|
|
276
272
|
</p>
|
|
277
273
|
|
|
278
|
-
<
|
|
279
|
-
<!-- Red -->
|
|
280
|
-
<a href="https://pytorch.org/">
|
|
281
|
-
<img src="https://img.shields.io/badge/PyTorch-EE4C2C?style=for-the-badge&logo=pytorch&logoColor=white" alt="PyTorch">
|
|
282
|
-
</a>
|
|
283
|
-
|
|
284
|
-
<!-- Orange -->
|
|
285
|
-
<a href="https://vllm.ai/">
|
|
286
|
-
<img src="https://img.shields.io/badge/vLLM-F97316?style=for-the-badge&logo=fastapi&logoColor=white" alt="vLLM">
|
|
287
|
-
</a>
|
|
288
|
-
|
|
289
|
-
<!-- Yellow -->
|
|
290
|
-
<a href="https://huggingface.co/">
|
|
291
|
-
<img src="https://img.shields.io/badge/HuggingFace-FFD21E?style=for-the-badge&logo=huggingface&logoColor=black" alt="HuggingFace">
|
|
292
|
-
</a>
|
|
293
|
-
|
|
294
|
-
<!-- Green -->
|
|
295
|
-
<a href="https://fastapi.tiangolo.com/">
|
|
296
|
-
<img src="https://img.shields.io/badge/FastAPI-009688?style=for-the-badge&logo=fastapi&logoColor=white" alt="FastAPI">
|
|
297
|
-
</a>
|
|
298
|
-
|
|
299
|
-
<!-- Blue -->
|
|
300
|
-
<a href="https://www.docker.com/">
|
|
301
|
-
<img src="https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=docker&logoColor=white" alt="Docker">
|
|
302
|
-
</a>
|
|
303
|
-
|
|
304
|
-
<!-- Indigo -->
|
|
305
|
-
<a href="https://github.com/">
|
|
306
|
-
<img src="https://img.shields.io/badge/CI/CD-181717?style=for-the-badge&logo=githubactions&logoColor=white" alt="CI/CD">
|
|
307
|
-
</a>
|
|
308
|
-
|
|
309
|
-
<!-- Violet -->
|
|
310
|
-
<a href="https://ollama.com/">
|
|
311
|
-
<img src="https://img.shields.io/badge/Ollama-7C3AED?style=for-the-badge&logo=llama&logoColor=white" alt="Ollama">
|
|
312
|
-
</a>
|
|
313
|
-
</p>
|
|
274
|
+
<h1>CodeFix-Env v0.2.3: Code Debugging Environment</h1>
|
|
314
275
|
|
|
276
|
+
<p>A sandboxed reinforcement learning environment for training and evaluating LLM agents on automated code debugging, and the fast, verifiable feedback loop that kind of training requires.</p>
|
|
315
277
|
|
|
316
278
|
<p align="center">
|
|
317
|
-
<a href="https://
|
|
318
|
-
<a href="https://
|
|
319
|
-
<a href="https://
|
|
320
|
-
<a href="
|
|
321
|
-
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green?style=flat-square"></a>
|
|
322
|
-
<a href="tests/"><img src="https://img.shields.io/badge/Tests-197%2F197%20Passing-brightgreen?style=flat-square"></a>
|
|
323
|
-
<a href="https://github.com/dhakarshailendra829/codefix-env"><img src="https://img.shields.io/github/stars/dhakarshailendra829/codefix-env?style=flat-square"></a>
|
|
279
|
+
<a href="https://github.com/dhakarshailendra829/codefix-env/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/dhakarshailendra829/codefix-env/ci.yml?branch=main&style=for-the-badge" alt="CI status"></a>
|
|
280
|
+
<a href="https://pypi.org/project/codefix-env/"><img src="https://img.shields.io/pypi/v/codefix-env?style=for-the-badge&color=blue" alt="PyPI version"></a>
|
|
281
|
+
<a href="https://github.com/dhakarshailendra829/codefix-env/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=for-the-badge" alt="Apache 2.0 License"></a>
|
|
282
|
+
<a href="tests/"><img src="https://img.shields.io/badge/tests-197%20passing-brightgreen?style=for-the-badge" alt="Tests passing"></a>
|
|
324
283
|
</p>
|
|
325
284
|
|
|
326
|
-
|
|
285
|
+
<p align="center">
|
|
286
|
+
<strong>
|
|
287
|
+
<a href="#quick-start">Quick Start</a> ·
|
|
288
|
+
<a href="ARCHITECTURE.md">Architecture</a> ·
|
|
289
|
+
<a href="SECURITY.md">Security</a> ·
|
|
290
|
+
<a href="CONTRIBUTING.md">Contributing</a>
|
|
291
|
+
</strong>
|
|
292
|
+
</p>
|
|
327
293
|
|
|
328
|
-
|
|
294
|
+
</div>
|
|
329
295
|
|
|
330
|
-
|
|
296
|
+
---
|
|
331
297
|
|
|
298
|
+
> **Status: active development.** The environment, sandbox, reward pipeline, and task registry are stable and tested. A trained-policy result and a larger, mined task set are in progress — see [Roadmap](#roadmap).
|
|
332
299
|
|
|
333
|
-
|
|
334
|
-
| :--- | :--- |
|
|
335
|
-
| **Train** | Large language models (LLMs) on code repair tasks. |
|
|
336
|
-
| **Evaluate** | AI agents on real debugging scenarios. |
|
|
337
|
-
| **Benchmark** | Code generation and reasoning capabilities. |
|
|
338
|
-
| **Build** | Automated debugging systems. |
|
|
300
|
+
---
|
|
339
301
|
|
|
340
|
-
|
|
302
|
+
## Table of Contents
|
|
303
|
+
|
|
304
|
+
- [Why CodeFix-Env?](#why-codefix-env)
|
|
305
|
+
- [Install](#install)
|
|
306
|
+
- [Quick Start](#quick-start)
|
|
307
|
+
- [Deployment](#deployment)
|
|
308
|
+
- [How It Works](#how-it-works)
|
|
309
|
+
- [Benchmark](#benchmark)
|
|
310
|
+
- [Capabilities](#capabilities)
|
|
311
|
+
- [Roadmap](#roadmap)
|
|
312
|
+
- [Contributing](#contributing)
|
|
313
|
+
- [Security](#security)
|
|
314
|
+
- [License](#license)
|
|
315
|
+
- [Citations](#citations)
|
|
341
316
|
|
|
342
317
|
---
|
|
343
318
|
|
|
344
|
-
|
|
319
|
+
## Why CodeFix-Env?
|
|
345
320
|
|
|
346
|
-
|
|
321
|
+
Training a coding agent to debug software requires more than static examples of correct code. It requires a tight loop: propose a fix, execute it against a real test suite, and receive a signal that reflects genuine progress rather than superficial activity.
|
|
347
322
|
|
|
348
|
-
|
|
349
|
-
Training Large Language Models (LLMs) for code generation and autonomous repair requires more than static data. Effective learning requires:
|
|
350
|
-
|
|
351
|
-
* **Authentic Scenarios:** Moving beyond synthetic examples to real-world debugging.
|
|
352
|
-
* **Tight Feedback Loops:** Providing immediate test results and error logs.
|
|
353
|
-
* **Measurable Progress:** Quantifiable metrics based on test pass rates.
|
|
354
|
-
* **Secure Execution:** Sandboxed environments to prevent unsafe code execution.
|
|
355
|
-
|
|
356
|
-
### 🟢 The Solution: CodeFix-Env
|
|
357
|
-
CodeFix-Env is a specialized environment designed for RL agents and LLMs to master code repair through:
|
|
358
|
-
|
|
359
|
-
* **Real-World Tasks:** 21 curated Python bugs ranging from logic errors to complex edge cases.
|
|
360
|
-
* **Test-Driven Feedback:** Agents receive granular execution data after every action.
|
|
361
|
-
* **Multi-Factor Rewards:** Reward signals based on test progress, code quality, and task completion.
|
|
362
|
-
* **Isolated Execution:** Built-in sandboxing with timeout protection for safe evaluations.
|
|
363
|
-
* **Structured Interaction:** Clean API for structured actions that LLMs can reliably generate.
|
|
364
|
-
|
|
365
|
-
### Workflow
|
|
366
|
-
```mermaid
|
|
367
|
-
graph TD
|
|
368
|
-
A[Agent receives buggy code] --> B[Analyze code & test failures]
|
|
369
|
-
B --> C[Generate action: e.g., edit_line]
|
|
370
|
-
C --> D[Environment executes action]
|
|
371
|
-
D --> E[Environment provides feedback]
|
|
372
|
-
|
|
373
|
-
subgraph Feedback Loop
|
|
374
|
-
E --> F[Test results & pass/fail counts]
|
|
375
|
-
E --> G[Code diff & change analysis]
|
|
376
|
-
E --> H[Shaped reward signals]
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
F & G & H --> I{Solution found?}
|
|
380
|
-
I -- No --> B
|
|
381
|
-
I -- Yes --> J[Task Complete]
|
|
382
|
-
```
|
|
383
|
-
---
|
|
323
|
+
We do that because SWE-bench<sup>1</sup> gave coding agents a scalable, realistic evaluation standard, built on full repositories and real GitHub issues. What it does not give is a fast enough loop for on-policy reinforcement learning, where thousands of cheap episodes per training step are typically required.
|
|
384
324
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
** Task Library**
|
|
388
|
-
- 21 carefully designed debugging tasks
|
|
389
|
-
- 3 difficulty levels: Easy (8), Medium (8), Hard (5)
|
|
390
|
-
- Each task includes buggy code, solution, test cases, and hints
|
|
391
|
-
- Covers real Python patterns: loops, recursion, algorithms, decorators
|
|
392
|
-
|
|
393
|
-
** LLM Integration**
|
|
394
|
-
- Works with HuggingFace Transformers ecosystem
|
|
395
|
-
- Compatible with training frameworks: SFT, DPO, GRPO, PPO
|
|
396
|
-
- Pre-built support for Qwen, Llama, CodeLlama, DeepSeek models
|
|
397
|
-
- Structured JSON action interface for LLM control
|
|
398
|
-
|
|
399
|
-
** Performance**
|
|
400
|
-
- Multiprocessing-based sandbox with timeout enforcement
|
|
401
|
-
- Per-test execution isolation
|
|
402
|
-
- 197 unit tests with 83% code coverage
|
|
403
|
-
- Automated CI/CD pipeline (Python 3.10, 3.11, 3.12)
|
|
404
|
-
|
|
405
|
-
** Developer Friendly**
|
|
406
|
-
- Gymnasium standard interface
|
|
407
|
-
- Async client for high-performance training
|
|
408
|
-
- Sync wrapper for notebooks
|
|
409
|
-
- FastAPI HTTP server for remote access
|
|
410
|
-
- Complete type hints and documentation
|
|
325
|
+
Most environments used for this today sit at one of two extremes: repository-scale benchmarks that are realistic but slow to sandbox, or ad-hoc code execution with no meaningful isolation at all. CodeFix-Env is built for the space between them.
|
|
411
326
|
|
|
412
|
-
|
|
327
|
+
CodeFix-Env is building that middle layer:
|
|
413
328
|
|
|
414
|
-
|
|
329
|
+
> a sandboxed, densely-rewarded reinforcement learning environment for single-function code repair, fast enough to serve as a rollout source, with a stated threat model rather than an assumed one
|
|
415
330
|
|
|
416
|
-
|
|
331
|
+
We do that by:
|
|
417
332
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
### Step 2: Create virual Environment
|
|
423
|
-
```bash
|
|
424
|
-
python3.11 -m venv .venv
|
|
425
|
-
source .venv/bin/activate (On mac)
|
|
426
|
-
.venv/Scripts/activate (On Windows)
|
|
427
|
-
```
|
|
428
|
-
### Step 3: Intall Package
|
|
429
|
-
#### For Basic Usage
|
|
430
|
-
```bash
|
|
431
|
-
pip install -e .
|
|
432
|
-
```
|
|
433
|
-
---
|
|
434
|
-
#### For Developement
|
|
435
|
-
```bash
|
|
436
|
-
pip install -e ".[dev]"
|
|
437
|
-
```
|
|
438
|
-
---
|
|
439
|
-
#### For LLM training (includes transformers, TRL, datasets)
|
|
440
|
-
```bash
|
|
441
|
-
pip install -e ".[llm]"
|
|
442
|
-
```
|
|
443
|
-
---
|
|
444
|
-
#### For everything
|
|
445
|
-
```bash
|
|
446
|
-
pip install -e ".[dev,llm]"
|
|
447
|
-
```
|
|
448
|
-
### Step 4: Verify Installation
|
|
449
|
-
```bash
|
|
450
|
-
python -c "from codefix_env import CodeFixEnvironment; print(' Installation successful!')"
|
|
451
|
-
```
|
|
452
|
-
---
|
|
453
|
-
## Usage & Development Guide
|
|
333
|
+
- executing every agent action inside a layered sandbox — static AST filtering, restricted builtins, and OS-level process isolation — documented in full in [SECURITY.md](SECURITY.md), including two hardening attempts that failed under load and were reverted rather than left unreported
|
|
334
|
+
- computing a dense, per-step reward from hidden test-pass-rate deltas, rather than a single pass/fail signal at episode end
|
|
335
|
+
- mining task candidates directly from real, merged bug-fix pull requests on GitHub, so tasks can be traced back to an actual historical defect (`scripts/mine_tasks.py`)
|
|
336
|
+
- publishing the environment as an installable, continuously tested package rather than a static research repository
|
|
454
337
|
|
|
455
|
-
|
|
456
|
-
```python
|
|
457
|
-
python << 'EOF'
|
|
458
|
-
from codefix_env import CodeFixEnvironment, CodeFixAction, ActionType
|
|
338
|
+
Our goal is to grow this into a task set and training result large enough to serve as a genuine benchmark and training ground for code-repair agents, in the same way SWE-bench did for repository-scale evaluation.
|
|
459
339
|
|
|
460
|
-
|
|
461
|
-
env = CodeFixEnvironment()
|
|
340
|
+
<sup>1</sup> https://arXiv:2607.XXXXX, 2026
|
|
462
341
|
|
|
463
|
-
|
|
464
|
-
obs = env.reset(difficulty="easy")
|
|
465
|
-
print(f"Task: {obs.task_id}")
|
|
466
|
-
print(f"Current Code:\n{obs.current_code}")
|
|
342
|
+
---
|
|
467
343
|
|
|
468
|
-
|
|
469
|
-
action = CodeFixAction(action_type=ActionType.RUN_TESTS)
|
|
470
|
-
result = env.step(action)
|
|
471
|
-
print(f"\nTest Results: {result.observation.tests_passed}/{result.observation.tests_total} passing")
|
|
472
|
-
print(f"Output:\n{result.observation.test_output}")
|
|
344
|
+
## Install
|
|
473
345
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
EOF
|
|
346
|
+
```bash
|
|
347
|
+
pip install codefix-env
|
|
477
348
|
```
|
|
478
349
|
|
|
479
|
-
|
|
480
|
-
|
|
350
|
+
For development, or to use the training extras:
|
|
351
|
+
|
|
481
352
|
```bash
|
|
353
|
+
git clone https://github.com/dhakarshailendra829/codefix-env.git
|
|
482
354
|
cd codefix-env
|
|
483
|
-
|
|
355
|
+
python -m venv venv
|
|
356
|
+
source venv/bin/activate # Windows: venv\Scripts\activate
|
|
357
|
+
pip install -e ".[dev]" # add ",llm" for transformers/TRL/accelerate
|
|
484
358
|
```
|
|
485
359
|
|
|
486
|
-
|
|
487
|
-
```bash
|
|
488
|
-
PYTHONPATH=src pytest tests/test_tasks.py::TestSolutionCorrectness -v
|
|
489
|
-
```
|
|
360
|
+
Verify:
|
|
490
361
|
|
|
491
|
-
To check code standards:
|
|
492
362
|
```bash
|
|
493
|
-
|
|
494
|
-
black --check src/ tests/ examples/
|
|
495
|
-
mypy src/codefix_env/ --ignore-missing-imports
|
|
363
|
+
codefix-server info
|
|
496
364
|
```
|
|
497
365
|
|
|
498
|
-
### 3. API Server Deployment
|
|
499
|
-
```bash
|
|
500
|
-
cd codefix-env
|
|
501
|
-
uvicorn src.codefix_env.server.app:app --reload --port 8000
|
|
502
|
-
```
|
|
503
366
|
---
|
|
504
|
-
## Usage Examples
|
|
505
367
|
|
|
506
|
-
|
|
507
|
-
|
|
368
|
+
## Quick Start
|
|
369
|
+
|
|
370
|
+
**Local environment** — run episodes directly in Python, no server required:
|
|
508
371
|
|
|
509
372
|
```python
|
|
510
373
|
from codefix_env import CodeFixEnvironment, CodeFixAction, ActionType
|
|
@@ -512,152 +375,129 @@ from codefix_env import CodeFixEnvironment, CodeFixAction, ActionType
|
|
|
512
375
|
env = CodeFixEnvironment()
|
|
513
376
|
obs = env.reset(task_id="easy-001-missing-return")
|
|
514
377
|
|
|
515
|
-
# 1. Run tests to identify failures
|
|
516
378
|
result = env.step(CodeFixAction(action_type=ActionType.RUN_TESTS))
|
|
517
|
-
print(f"
|
|
379
|
+
print(f"{result.observation.tests_passed}/{result.observation.tests_total} tests passing")
|
|
518
380
|
|
|
519
|
-
# 2. Apply a targeted fix
|
|
520
381
|
result = env.step(CodeFixAction(
|
|
521
382
|
action_type=ActionType.EDIT_LINE,
|
|
522
383
|
line_number=3,
|
|
523
|
-
new_content=" return result"
|
|
384
|
+
new_content=" return result",
|
|
524
385
|
))
|
|
525
386
|
|
|
526
|
-
# 3. Final Verification & Submission
|
|
527
387
|
result = env.step(CodeFixAction(action_type=ActionType.SUBMIT_FIX))
|
|
528
|
-
print(
|
|
529
|
-
print(f"Final Reward: {result.reward:.3f}")
|
|
388
|
+
print("solved" if result.observation.all_tests_pass else "not solved", result.reward)
|
|
530
389
|
```
|
|
531
390
|
|
|
532
|
-
|
|
533
|
-
Programmatically interact with the task database.
|
|
391
|
+
**Server mode** — expose the environment over HTTP for remote or multi-language clients:
|
|
534
392
|
|
|
535
|
-
```
|
|
536
|
-
|
|
393
|
+
```bash
|
|
394
|
+
codefix-server serve --port 8000
|
|
395
|
+
```
|
|
537
396
|
|
|
538
|
-
|
|
539
|
-
print(f"Total tasks by difficulty: {task_count()}")
|
|
397
|
+
**Task inspection** — list and filter the task registry:
|
|
540
398
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
399
|
+
```bash
|
|
400
|
+
codefix-server tasks
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
**Baseline evaluation** — run oracle and random policies across the full task set:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
python scripts/run_baseline_eval.py --episodes 3
|
|
545
407
|
```
|
|
546
408
|
|
|
547
409
|
---
|
|
548
410
|
|
|
549
|
-
##
|
|
411
|
+
## Deployment
|
|
550
412
|
|
|
551
|
-
|
|
552
|
-
Deploy the environment as a service to scale LLM evaluations across multiple agents.
|
|
413
|
+
The repository includes a `Dockerfile` for running the environment as a standalone service:
|
|
553
414
|
|
|
554
415
|
```bash
|
|
555
|
-
|
|
556
|
-
|
|
416
|
+
docker build -t codefix-env .
|
|
417
|
+
docker run -p 8000:8000 codefix-env
|
|
557
418
|
```
|
|
558
419
|
|
|
559
|
-
|
|
560
|
-
Export environment states into `.jsonl` formats for fine-tuning models like Llama or Qwen.
|
|
561
|
-
|
|
562
|
-
```python
|
|
563
|
-
import json
|
|
564
|
-
from codefix_env import CodeFixClient
|
|
565
|
-
|
|
566
|
-
async def collect_trajectories():
|
|
567
|
-
async with CodeFixClient("http://localhost:8000") as client:
|
|
568
|
-
obs = await client.reset(difficulty="medium")
|
|
569
|
-
dataset_entry = {
|
|
570
|
-
"instruction": f"Fix the following code: {obs.current_code}",
|
|
571
|
-
"context": obs.test_output,
|
|
572
|
-
"metadata": {"task_id": obs.task_id}
|
|
573
|
-
}
|
|
574
|
-
# Append to training_data.jsonl....
|
|
575
|
-
```
|
|
420
|
+
Set `CODEFIX_REWARD_MODEL_PATH` if using a trained neural reward checkpoint (see [ARCHITECTURE.md](ARCHITECTURE.md)). No other environment variables are required for the default, rule-based reward configuration.
|
|
576
421
|
|
|
577
|
-
|
|
578
|
-
Connect an LLM directly to the environment loop.
|
|
422
|
+
---
|
|
579
423
|
|
|
580
|
-
|
|
581
|
-
from transformers import pipeline
|
|
582
|
-
from codefix_env import CodeFixEnvironment
|
|
424
|
+
## How It Works
|
|
583
425
|
|
|
584
|
-
|
|
585
|
-
fixer = pipeline("text-generation", model="Qwen/Qwen2.5-Coder-7B")
|
|
426
|
+
When an episode runs, CodeFix-Env:
|
|
586
427
|
|
|
587
|
-
|
|
588
|
-
|
|
428
|
+
1. **Loads** a task — a buggy function, a hidden test suite, and graduated hints
|
|
429
|
+
2. **Receives** a structured action from the agent: run tests, edit a line, insert, delete, request a hint, view the code, or submit
|
|
430
|
+
3. **Executes** any code-mutating action inside the sandbox, isolated from the host process
|
|
431
|
+
4. **Computes** a unified diff against the original code and a dense, shaped reward from the test-pass-rate change
|
|
432
|
+
5. **Returns** the updated observation, including test output and the diff, so the agent can decide its next action
|
|
433
|
+
6. **Terminates** the episode on a full solve, an explicit submission, or the step budget running out
|
|
589
434
|
|
|
590
|
-
|
|
591
|
-
prompt = f"Fix this Python code based on these errors: {obs.test_output}\nCode:\n{obs.current_code}"
|
|
592
|
-
suggestion = fixer(prompt)
|
|
593
|
-
```
|
|
435
|
+
Full design detail, including the reward formula and the sandbox's layered isolation model, is in [ARCHITECTURE.md](ARCHITECTURE.md).
|
|
594
436
|
|
|
595
437
|
---
|
|
596
438
|
|
|
597
|
-
##
|
|
439
|
+
## Benchmark
|
|
598
440
|
|
|
441
|
+
Regenerate these numbers with `python scripts/run_baseline_eval.py --episodes 3`.
|
|
599
442
|
|
|
600
|
-
|
|
601
|
-
| :--- | :--- |
|
|
602
|
-
| `CodeFixEnvironment` | Local execution engine for debugging tasks. |
|
|
603
|
-
| `CodeFixClient` | Async client for interacting with a remote server. |
|
|
604
|
-
| `env.step(action)` | Executes an `ActionType` (EDIT, RUN_TESTS, SUBMIT). |
|
|
605
|
-
| `Difficulty` | Enum: `EASY`, `MEDIUM`, `HARD`. |
|
|
606
|
-
| `BugCategory` | Categories: `SYNTAX`, `LOGIC`, `DATA_STRUCTURE`, `ALGORITHM`. |
|
|
443
|
+
<!-- BENCHMARK-START -->
|
|
607
444
|
|
|
608
|
-
|
|
445
|
+
Oracle policy (applies the known-correct fix) versus a random policy, across all 21 tasks:
|
|
609
446
|
|
|
610
|
-
|
|
611
|
-
|
|
447
|
+
| Policy | Easy | Medium | Hard |
|
|
448
|
+
|---|---|---|---|
|
|
449
|
+
| Oracle | 100% | 87.5% | 60% |
|
|
450
|
+
| Random | 0% | 0% | 20% |
|
|
612
451
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
452
|
+
No trained-policy result yet — this compares two fixed baselines to confirm the reward signal discriminates genuine problem-solving from undirected action. A GRPO training result is in progress; see [Roadmap](#roadmap).
|
|
453
|
+
|
|
454
|
+
<!-- BENCHMARK-END -->
|
|
616
455
|
|
|
617
|
-
# Static Analysis
|
|
618
|
-
ruff check src/ # Linting
|
|
619
|
-
black --check src/ # Formatting
|
|
620
|
-
mypy src/ # Type Checking
|
|
621
|
-
```
|
|
622
456
|
---
|
|
623
457
|
|
|
624
|
-
|
|
458
|
+
## Capabilities
|
|
625
459
|
|
|
626
|
-
|
|
460
|
+
| | |
|
|
461
|
+
|---|---|
|
|
462
|
+
| **Sandboxed execution** | Static AST filtering, restricted builtins, and OS-level process isolation, with a documented threat model |
|
|
463
|
+
| **Dense reward shaping** | Per-step reward from test-pass-rate deltas, hint-usage and step-count penalties, and a solve bonus |
|
|
464
|
+
| **Graded task registry** | 21 tasks across easy, medium, and hard tiers, each with hidden tests and progressive hints |
|
|
465
|
+
| **Task mining pipeline** | Extracts candidate tasks from real, merged GitHub bug-fix pull requests for human review |
|
|
466
|
+
| **Server and async client** | FastAPI HTTP server with a session-scoped API, plus an async client for training loops |
|
|
467
|
+
| **Framework-compatible** | Gymnasium-style `reset()`/`step()`/`state()` interface; usable with SFT, DPO, GRPO, and PPO training code |
|
|
468
|
+
| **CI-gated** | 197 tests, linting, and type checking on every change, across Python 3.10 through 3.12 |
|
|
627
469
|
|
|
628
|
-
|
|
470
|
+
---
|
|
629
471
|
|
|
630
|
-
|
|
631
|
-
| :--- | :--- |
|
|
632
|
-
| 🟢 **Qwen 1.5B, 7B, 14B** | Alibaba's instruction models |
|
|
633
|
-
| 🟢 **Llama 2-7B-Chat** | Meta's foundation model |
|
|
634
|
-
| 🟢 **CodeLlama 7B, 13B, 34B** | Specialized for code |
|
|
635
|
-
| 🟢 **DeepSeek Coder 1.3B, 6.7B** | Chinese LLM for code |
|
|
636
|
-
| 🟢 **Mistral 7B** | Open-source efficient model |
|
|
472
|
+
## Roadmap
|
|
637
473
|
|
|
638
|
-
|
|
474
|
+
- Closed-loop RL training result: fine-tune a small open-weight code model against the environment and publish a measured pass-rate curve
|
|
475
|
+
- A trained checkpoint for the optional learned reward model, calibrated against oracle judgment
|
|
476
|
+
- Task registry expansion from 21 to several hundred tasks, mined and reviewed from real repositories
|
|
477
|
+
- Multi-file task support, extending beyond single-function scope
|
|
478
|
+
- Container-level sandbox isolation (namespace and capability restrictions, seccomp filtering)
|
|
479
|
+
- Support for a second programming language
|
|
480
|
+
- Horizontally scalable session handling for distributed rollout collection
|
|
481
|
+
- Listing on the OpenEnv Hub
|
|
639
482
|
|
|
640
|
-
|
|
483
|
+
---
|
|
641
484
|
|
|
642
|
-
|
|
643
|
-
| :--- | :--- |
|
|
644
|
-
| 🟢 **SFT** | Supervised fine-tuning |
|
|
645
|
-
| 🟢 **DPO** | Direct preference optimization |
|
|
646
|
-
| 🟢 **GRPO** | Group relative policy optimization |
|
|
647
|
-
| 🟢 **PPO** | Proximal policy optimization |
|
|
485
|
+
## Contributing
|
|
648
486
|
|
|
649
|
-
|
|
487
|
+
Issues and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for local setup, the task-authoring template, and the pull request workflow.
|
|
650
488
|
|
|
651
|
-
|
|
489
|
+
---
|
|
652
490
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
| 🟢 **vLLM** | Fast LLM serving |
|
|
657
|
-
| 🟢 **Ollama** | Local model deployment |
|
|
658
|
-
| 🟢 **Docker** | Containerization |
|
|
659
|
-
| 🟢 **GitHub Actions** | CI/CD |
|
|
491
|
+
## Security
|
|
492
|
+
|
|
493
|
+
Execution isolation is treated as a first-class design concern, not an afterthought — including reporting what the current sandbox does not protect against. See [SECURITY.md](SECURITY.md) for the full threat model and for responsible disclosure of any suspected sandbox escape.
|
|
660
494
|
|
|
661
|
-
</div>
|
|
662
495
|
---
|
|
663
|
-
|
|
496
|
+
|
|
497
|
+
## License
|
|
498
|
+
|
|
499
|
+
Apache License 2.0 — see [LICENSE](LICENSE).
|
|
500
|
+
|
|
501
|
+
## Citations
|
|
502
|
+
<sup>2</sup> Dhakad, S. CodeFix-Env: A Sandboxed Reinforcement Learning Environment for Automated Code Debugging. arXiv:2607.XXXXX, 2026.
|
|
503
|
+
|