Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions aworld/sandbox/tool_servers/terminal/src/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ async def run_code(
if isinstance(output_format, FieldInfo):
output_format = output_format.default

# Timeout: env TERMINAL_TIMEOUT overrides parameter/default when set
env_timeout = os.environ.get("TERMINAL_TIMEOUT")
if env_timeout is not None:
try:
timeout = int(env_timeout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation allows for a negative timeout if TERMINAL_TIMEOUT is set to a negative number. This can lead to undefined behavior in asyncio.wait_for, which expects a non-negative value for the timeout. It's better to validate that the timeout is non-negative before assigning it.

Suggested change
timeout = int(env_timeout)
parsed_timeout = int(env_timeout)
if parsed_timeout >= 0:
timeout = parsed_timeout

except ValueError:
pass # keep current timeout if env value is not a valid integer

output_data = ""
command_id = str(uuid.uuid4())
try:
Expand Down