Sets resource limits for the subprocess based on the provided policy.
(policy: BashToolPolicy)
| 76 | |
| 77 | |
| 78 | def _set_resource_limits(policy: BashToolPolicy) -> None: |
| 79 | """Sets resource limits for the subprocess based on the provided policy.""" |
| 80 | try: |
| 81 | resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) |
| 82 | if policy.max_memory_bytes: |
| 83 | resource.setrlimit( |
| 84 | resource.RLIMIT_AS, |
| 85 | (policy.max_memory_bytes, policy.max_memory_bytes), |
| 86 | ) |
| 87 | if policy.max_file_size_bytes: |
| 88 | resource.setrlimit( |
| 89 | resource.RLIMIT_FSIZE, |
| 90 | (policy.max_file_size_bytes, policy.max_file_size_bytes), |
| 91 | ) |
| 92 | if policy.max_child_processes: |
| 93 | resource.setrlimit( |
| 94 | resource.RLIMIT_NPROC, |
| 95 | (policy.max_child_processes, policy.max_child_processes), |
| 96 | ) |
| 97 | except (ValueError, OSError) as e: |
| 98 | logger.warning("Failed to set resource limits: %s", e) |
| 99 | |
| 100 | |
| 101 | class ExecuteBashTool(BaseTool): |