Skip to content

fix(tools): enforce ExecuteBashTool resource limits that are set to 0 - #7984

Open
Fruiterer333 wants to merge 1 commit into
google:mainfrom
Fruiterer333:fix/bash-tool-zero-resource-limits
Open

Fruiterer333 wants to merge 1 commit into
google:mainfrom
Fruiterer333:fix/bash-tool-zero-resource-limits

Conversation

@Fruiterer333

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

_set_resource_limits checked each limit with if policy.max_file_size_bytes:. A limit of 0 is falsy, so setrlimit was never called for it and the command ran with no limit. BashToolPolicy(max_file_size_bytes=0) let a command write files of any size, and max_child_processes=0 did not stop it from starting child processes.

Solution:

The three limits are now checked with is not None. None is still the default and still means no limit; 0 is now passed to setrlimit like any other value. The BashToolPolicy docstring now says that 0 is enforced.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.

  • All unit tests pass locally.
    Added two tests to tests/unittests/tools/test_bash_tool.py; both fail on main:

  • test_zero_resource_limits_are_enforced: with all three limits at 0, setrlimit is called for RLIMIT_AS, RLIMIT_FSIZE and RLIMIT_NPROC with (0, 0).

  • test_zero_file_size_limit_blocks_file_writes: with max_file_size_bytes=0, a real dd command that writes 4096 bytes fails and the file stays empty.

$ pytest tests/unittests/tools/test_bash_tool.py
28 passed

Manual End-to-End (E2E) Tests:

Ran the reproduction script from the issue:

# before (main)
max_file_size_bytes=1024: returncode=-25, bytes written=1024
max_file_size_bytes=0: returncode=0, bytes written=4096
 
# after
max_file_size_bytes=1024: returncode=-25, bytes written=1024
max_file_size_bytes=0: returncode=-25, bytes written=0

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules. (N/A: no dependent changes)

Additional context

I used Claude Code to help find the issue and draft the change; I reproduced the bug and verified the fix and tests locally.

@Fruiterer333
Fruiterer333 force-pushed the fix/bash-tool-zero-resource-limits branch from b3314dd to af51dd0 Compare November 4, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExecuteBashTool ignores resource limits that are set to 0

2 participants