-
Notifications
You must be signed in to change notification settings - Fork 37
Security and Code Quality Improvements #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+291
−52
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use shlex.quote() instead of Python repr for proper shell escaping when wrapping commands with timeout. This fixes syntax errors when commands contain special characters like parentheses (e.g., in git apply patches). Also update test_eval_timeout to expect the new timeout message format. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- DockerTerminal.close(): Close docker_client to release connection pool resources. Previously only the container was stopped but the client connection was never closed, causing pool exhaustion after ~10 iterations. - ShellSession.close(): Add process.wait() after terminate() to avoid zombie processes. If wait times out, forcefully kill the process. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The previous fix closed the Docker client in close() to prevent connection leaks, but setting docker_client = None broke terminal reuse since setup_container() would fail with 'NoneType' has no attribute 'containers'. This fix converts docker_client to a lazy-initialized property that recreates the client on demand if it was previously closed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The close() method was only stopping the listener thread but not closing FileHandler instances, leaving file handles open. This caused processes to hang indefinitely when many loggers were created (e.g., per-agent loggers in parallel evaluation). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Previously, _load_prompt_template() created a Jinja2 Environment without a loader, causing include and from directives to fail with no loader for this environment specified error. Now uses FileSystemLoader with the templates parent directory as root, enabling relative includes for modular prompt templates. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Allows users to specify a custom root directory for the Jinja2
FileSystemLoader, enabling modular template structures with shared
components across sibling directories.
Example usage:
agent_args = AgentArgs(
system_prompt="prompts/exploration/main.jinja",
prompt_loader_root="prompts/" # enables common/ includes
)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MarcCote
approved these changes
Jan 7, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
AFTER #325
Security and Code Quality Improvements
Summary
This PR addresses security vulnerabilities and code quality issues identified during a comprehensive codebase review. The changes focus on preventing command injection, fixing resource leaks, and improving input validation across LLM providers and terminal operations.
Critical Security Fixes
Command Injection Prevention
shlex.quote()to all shell command path interpolations (cat,mkdir,echo,treecommands)cp -rcommand to quote source and target pathsPath Traversal Fix
==path/*instead of==path*) preventing escape via paths like/testbed_evil/High Priority Fixes
HTTP Client Timeouts
Input Validation
hasattr()validation before accessing response attributes.envfile parsing with proper quote handlingMedium Priority Improvements
Resource Management
close()method for HTTP client cleanupclose()methods to properly release HTTP clientsclose()methods that callsuper().close()and invalidate cachesMemory Management
maxsize=10)maxsize=5)Input Validation
max_depthparameter (1-20)Files Changed
debug_gym/gym/workspace.pydebug_gym/gym/terminals/local.pydebug_gym/gym/envs/swe_bench_debug.pydebug_gym/gym/envs/r2egym.pydebug_gym/llms/base.pydebug_gym/llms/openai.pydebug_gym/llms/anthropic.pydebug_gym/llms/azure_openai.pydebug_gym/llms/copilot.pydebug_gym/llms/huggingface.pydebug_gym/agents/simple_agent.pyTesting