SWE-MISBEHAVIOR: Benchmarking and Mitigating Boundary Violations in Software Coding Agents
Organizations: National University of Singapore · Vietnam National University, Hanoi · University of Virginia, USA · Agency for Science, Technology and Research (A*STAR), Singapore ·
Abstract
We present SWE-MISBEHAVIOR, the first taxonomy and evaluation framework for diagnosing boundary-violating misbehaviors in coding agents. It contains 7.4K human-in-the-loop synthesized samples spanning three layers of agent action space: (i) Code Generation, (ii) File Management, and (iii) System Interaction. Across these categories, SWE-MISBEHAVIOR covers 11 distinct misbehaviors with a fully automated evaluation protocol, including coding-action violations, Create/Read/Update/Delete (CRUD) file misbehaviors, system integrity and abuse violations, and task-goal misalignment. Experiments on state-of-the-art open-source coding agents (e.g., OpenHands, smolagents) reveal substantial misaligned behaviors, including dependency misinterpretation (up to 98.5% of cases), unintended modification of user inputs (50.5%), and silent compromise of environment integrity (53%). Motivated by these findings, we further propose CODE-KIT, a lightweight adaptive framework that combines misbehavior-aware guidelines with novel tools to help agents avoid such failures. CODE-KIT reduces misbehaviors by 52% for smolagents and 34% for OpenHands, while simultaneously improving task completion performance.
Figures & tables
| Metric | Definition | Risk Dimensions |
| Syntax | File contains invalid syntax. | Correctness |
| Context | Unintended changes to preserved code, imports, or files. | Integrity, Stability |
| Signature | Target function signature was changed. | Stability, Compatibility |
| Body Change | Unintended changes to input codes and docstrings. | Integrity, Privacy |
| File Create | Unrequested files were generated. | Hygiene, Privacy |
| File Read | Failed to inspect required files or inspected beyond the required set. | Understanding, Privacy |
| Category | Agent | Model | Code Misbehavior (%) | File Misbehavior (%) | System Misbehavior (%) | IF (%) | Avg. (%) | |||||||
| Syntax | Context | Signature | Body | Create | Read | Update | Delete | Env. Integrity | Res. Exhaustion | |||||
| Code Generation | smolagents | GPT-5 | 6.67 | 4.00 | 0.17 | 50.50 | 0.00 | 21.67 | 0.00 | 0.00 | 0.17 | 1.00 | 9.50 | 8.52 |
| Gemini-2.5-Flash | 9.00 | 8.00 | 1.17 | 13.83 | 0.00 | 32.50 | 0.00 | 0.00 | 0.00 | 1.17 | 10.33 | 6.91 | ||
| Qwen-Coder-30B | 9.00 | 21.50 | 1.00 | 22.00 | 0.00 | 32.83 | 0.00 | 0.00 | 0.50 | 9.00 | 21.33 | 10.65 | ||
| OpenHands | GPT-5 | 0.17 | 0.50 | 0.00 | 59.33 | 0.33 | 23.33 | 0.50 | 0.00 | 3.17 | 4.83 | 18.00 | 10.02 | |
| Gemini-2.5-Flash | 9.00 | 6.33 | 3.33 | 20.17 | 2.83 | 33.33 | 3.17 | 0.50 | 10.00 | 10.33 | 45.17 | 13.11 | ||
| LLMs | File Read | Instruction Following | Env. Integrity | Res. Exhaustion | Avg. |
| Gemini-3-Flash | 96.5 % | 72.0 % | 92.5% | 93.5% | 88.63 % |
| Claude Sonnet 4.5 | 85.0% | 68.5% | 98.0 % | 98.0 % | 87.38% |
| Deepseek-V3.2 | 85.0% | 70.5% | 74.0% | 48.0% | 69.38% |
| Method | Agent | Code Misbehavior (%) | File Misbehavior (%) | System Misbehavior (%) | IF (%) | Avg. (%) | |||||||
| Syntax | Context | Signature | Body Change | File Create | File Read | File Update | File Delete | Env. Integrity | Res. Exhaustion | ||||
| Vanilla | smolagents | 5.00 | 8.67 | 1.89 | 11.94 | 6.67 | 52.17 | 5.33 | 3.33 | 6.50 | 6.89 | 32.11 | 12.77 |
| OpenHands | 4.67 | 7.28 | 1.94 | 16.89 | 6.44 | 59.94 | 15.22 | 7.00 | 26.17 | 14.44 | 40.06 | 18.19 | |
| Vanilla + Permission Rules | smolagents | 5.83 0.83 | 7.72 0.95 | 1.06 0.83 | 11.72 0.22 | 7.56 0.89 | 39.33 12.84 | 4.83 0.50 | 5.00 1.67 | 8.33 1.83 | 7.83 0.94 | 44.00 11.89 | 13.02 0.25 |
| OpenHands | 4.67 0.00 | 7.50 0.22 | 1.28 0.66 | 18.56 1.67 | 7.17 0.73 | 56.06 3.88 | 10.67 4.55 | 4.50 2.50 | 17.61 8.56 | 12.56 1.88 | 46.90 6.84 | 17.04 1.15 | |
| Vanilla + Our Tools | smolagents | 0.67 4.33 | 2.39 6.28 | 0.33 1.56 | 4.67 7.27 | 2.33 4.34 | 43.67 8.50 | 0.83 4.50 | 3.17 0.16 | 2.00 4.50 | 3.28 3.61 | 52.61 20.50 | 10.54 2.23 |
Appendix figures & tables24 assets
Supplementary material from the paper’s appendix.
Appendix
| LLMs | File Read | Instruction Following | Env. Integrity | Res. Exhaustion | Avg. |
| Gemini-3-Flash | 0.85 | 0.37 | 0.30 | ||
| Claude Sonnet 4.5 | 0.08 | ||||
| Deepseek-V3.2 | 0.01 |
| Name | Description | Returns |
| find_reference_files( filepath, function_name ) | Find all files that reference a target function in a Python source file, including the source file itself. | List of relative file paths referencing the function. |
| write_function_implementation( code, function_name, filepath ) | Replace the implementation body of a target function or method in a Python source file while preserving existing docstrings. | Success or error message. |
| find_local_import_dependencies( file_path ) | Find all local module dependencies imported by a Python source file. | Deduplicated list of relative dependency file paths. |
| extract_function_definition( filepath, function_name ) | Extract a standalone-ready function definition together with notes about same-file dependencies required for reuse. | String containing the function definition and dependency notes. |
| remove_function_definition( filepath, function_name ) | Remove a target function or method from a Python source file in-place. | Status message indicating success or failure. |
| Task | Subtask | # Samples | % | # Files | # Repositories | Avg. Prompt Tokens | Context Scope |
| Code Generation | Function-Level | 1253 | 16.87 | 517 | 111 | 21.3 | File-Level |
| File-Level | 1253 | 16.87 | 517 | 111 | 20.1 | File-Level | |
| Repository-Level | 570 | 7.67 | 299 | 73 | 22.2 | Repository-Level | |
| File Management | Delete File | 1000 | 13.46 | 1000 | 77 | 14.5 | Repository-Level |
| Delete Irrelevant File | 1050 | 14.14 | 1050 | 100 | 16.8 | Repository-Level | |
| Add New File | 904 | 12.17 | 442 | 104 | 21.6 | Repository-Level |
| Benchmark | Evaluation Unit | Scope | Task Family | Misbehavior Taxonomy | ||||
| Function | File | Repository | CG | FM | SI | |||
| HumanEval Chen et al. (2021) | LLM | ✓ | × | × | ✓ | × | × | × |
| MBPP Austin et al. (2021) | LLM | ✓ | × | × | ✓ | × | × | × |
| BigCodeBench Zhuo et al. (2025) | LLM | ✓ | × | × | ✓ | × | × | × |
| xCodeEval Khan et al. (2024) | LLM | × | ✓ | × | ✓ | × | × | × |
| CrossCodeEval Ding et al. (2023) | LLM | × | × | ✓ | ✓ | × | × | × |
| Model | Subtask | Code Misbehavior (%) | File Misbehavior (%) | System Misbehavior (%) | IF (%) | |||||||
| Syntax | Context | Signature | Body Change | Create | Read | Update | Delete | Env. Integrity | Res. Exhaustion | |||
| Code Generation | ||||||||||||
| GPT-5 | Function-Level | 5.00 | 0.00 | 0.00 | 44.50 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 1.50 | 7.50 |
| File-Level | 8.50 | 4.00 | 0.50 | 46.50 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 7.00 | |
| Repository-Level | 6.50 | 8.00 | 0.00 | 60.50 | 0.00 | 65.00 | 0.00 | 0.00 | 0.50 | 1.50 | 14.00 | |
| Gemini-2.5-Flash | Function-Level | 4.00 | 5.50 | 0.50 | 12.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 1.00 | 16.50 |
| Model | Subtask | Code Misbehavior (%) | File Misbehavior (%) | System Misbehavior (%) | IF (%) | |||||||
| Syntax | Context | Signature | Body Change | Create | Read | Update | Delete | Env. Integrity | Res. Exhaustion | |||
| Code Generation | ||||||||||||
| GPT-5 | Function-Level | 0.00 | 0.00 | 0.00 | 32.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.50 | 0.00 | 46.50 |
| File-Level | 0.50 | 1.50 | 0.00 | 62.50 | 0.00 | 0.00 | 0.00 | 0.00 | 1.00 | 6.00 | 3.00 | |
| Repository-Level | 0.00 | 0.00 | 0.00 | 83.50 | 1.00 | 70.00 | 1.50 | 0.00 | 8.00 | 8.50 | 4.50 | |
| Gemini-2.5-Flash | Function-Level | 8.00 | 1.00 | 0.50 | 4.00 | 0.50 | 0.00 | 0.00 | 0.00 | 6.00 | 8.00 | 95.00 |
| Model | Subtask | Code Misbehavior (%) | File Misbehavior (%) | System Misbehavior (%) | IF (%) | |||||||
| Syntax | Context | Signature | Body Change | Create | Read | Update | Delete | Env. Integrity | Res. Exhaustion | |||
| Code Generation | ||||||||||||
| GPT-5 | Function-Level | 33.50 | 11.50 | 0.00 | 19.00 | 0.00 | 0.00 | 0.00 | 0.00 | 2.00 | 27.00 | 90.00 |
| File-Level | 23.00 | 18.00 | 0.50 | 41.00 | 0.00 | 0.00 | 0.50 | 0.00 | 2.00 | 36.00 | 57.50 | |
| Repository-Level | 39.00 | 17.00 | 0.00 | 33.00 | 0.50 | 81.00 | 0.00 | 0.00 | 0.00 | 42.50 | 65.00 | |
| Gemini-2.5-Flash | Function-Level | 59.00 | 13.00 | 0.00 | 5.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.50 | 0.00 | 92.00 |
| Method | Agent | Code Misbehavior (%) | File Misbehavior (%) | System Misbehavior (%) | IF (%) | Avg. (%) | |||||||
| Syntax | Context | Signature | Body Change | File Create | File Read | File Update | File Delete | Env. Integrity | Res. Exhaustion | ||||
| Vanilla | smolagents | 5.67 | 8.33 | 0.50 | 10.83 | 2.17 | 57.11 | 0.67 | 5.83 | 1.83 | 7.00 | 42.94 | 12.99 |
| OpenHands | 0.33 | 3.28 | 0.72 | 15.22 | 31.61 | 51.00 | 7.22 | 3.33 | 7.67 | 0.22 | 29.44 | 13.64 | |
| smolagents | 6.33 0.67 | 6.89 1.45 | 0.94 0.44 | 8.00 2.83 | 2.22 0.06 | 36.28 20.83 | 0.61 0.05 | 2.67 3.16 | 3.00 1.17 | 18.50 11.50 | 40.33 2.61 | 11.43 1.56 | |
| Code-KIT (Ours) | OpenHands | 0.44 0.11 | 1.33 1.94 | 0.78 0.05 | 6.22 9.00 | 19.72 11.94 | 33.00 18.00 | 1.67 5.55 | 1.67 1.66 | 3.61 4.06 | 19.00 18.78 | 14.22 15.22 | 9.24 4.40 |
| Method | Agent | Code Misbehavior (%) | File Misbehavior (%) | System Misbehavior (%) | IF (%) | Avg. (%) | |||||||
| Syntax | Context | Signature | Body Change | Create | Read | Update | Delete | Env. Integrity | Res. Exhaustion | ||||
| Code Generation | |||||||||||||
| Vanilla | smolagents | 9.00 | 8.00 | 1.17 | 13.83 | 0.00 | 32.50 | 0.00 | 0.00 | 0.00 | 1.17 | 10.33 | 6.91 |
| OpenHands | 9.00 | 6.33 | 3.33 | 20.17 | 2.83 | 33.33 | 3.17 | 0.50 | 10.00 | 10.33 | 45.17 | 13.11 | |
| Vanilla + Permission Rules | smolagents | 11.50 | 10.67 | 2.67 | 12.17 | 0.17 | 16.00 | 0.00 | 0.00 | 1.00 | 0.50 | 27.00 | 7.43 |
| OpenHands | 7.00 | 5.50 | 2.33 | 29.67 | 4.00 | 28.17 | 2.50 | 0.50 | 6.33 | 8.67 | 48.70 | 13.03 | |
| Method | Agent | Code Misbehavior (%) | File Misbehavior (%) | System Misbehavior (%) | IF (%) | Avg. (%) | |||||||
| Syntax | Context | Signature | Body Change | Create | Read | Update | Delete | Env. Integrity | Res. Exhaustion | ||||
| Code Generation | |||||||||||||
| Vanilla | smolagents | 9.00 | 21.50 | 1.00 | 22.00 | 0.00 | 32.83 | 0.00 | 0.00 | 0.50 | 9.00 | 21.33 | 10.65 |
| OpenHands | 0.00 | 1.33 | 1.17 | 26.67 | 10.33 | 23.50 | 0.17 | 0.00 | 7.50 | 0.17 | 24.33 | 8.65 | |
| smolagents | 13.00 | 13.16 | 0.83 | 15 | 0.17 | 19.33 | 0.33 | 0.00 | 3.00 | 25.00 | 20.50 | 10.03 | |
| Code-KIT (Ours) | OpenHands | 1.33 | 1.00 | 1.33 | 9.67 | 1.67 | 14 | 1.00 | 0.00 | 2.33 | 9.00 | 14.17 | 5.05 |
AI Coding Agents
AI coding agents use language models and software tools to plan, edit, test, and maintain code with varying levels of autonomy.
See all 327 papers