Skip to content

Commit

Permalink
user parameter for bash() and python() tools (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire authored Sep 11, 2024
1 parent 360bf84 commit 5b7f186
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [score()](https://inspect.ai-safety-institute.org.uk/solvers.html#sec-scoring-in-solvers) function for accessing scoring logic from within solvers.
- `system_message()` now supports custom parameters and interpolation of `metadata` values from `Sample`.
- `generate()` solver now accepts arbitrary generation config params.
- `bash()` and `python()` tools now have a `user` parameter for choosing an alternate user to run code as.
- Input event for recording screen input in sample transcripts.
- Record to sample function for CSV and JSON dataset readers can now return multiple samples.
- Added `debug_errors` option to `eval()` to raise task errors (rather than logging them) so they can be debugged.
Expand Down
14 changes: 10 additions & 4 deletions src/inspect_ai/tool/_tools/_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@


@tool
def bash(timeout: int | None = None) -> Tool:
def bash(timeout: int | None = None, user: str | None = None) -> Tool:
"""Bash shell command execution tool.
Execute bash shell commands using a sandbox environment (e.g. "docker").
Args:
timeout (int | None): Timeout (in seconds) for command.
user (str | None): User to execute commands as.
Returns:
String with command output (stdout) or command error (stderr).
Expand All @@ -26,7 +27,9 @@ async def execute(cmd: str) -> str:
Returns:
The output of the command.
"""
result = await sandbox().exec(cmd=["bash", "-c", cmd], timeout=timeout)
result = await sandbox().exec(
cmd=["bash", "-c", cmd], timeout=timeout, user=user
)
if result.success:
return result.stdout
else:
Expand All @@ -38,13 +41,14 @@ async def execute(cmd: str) -> str:


@tool
def python(timeout: int | None = None) -> Tool:
def python(timeout: int | None = None, user: str | None = None) -> Tool:
"""Python code execution tool.
Execute Python code using a sandbox environment (e.g. "docker").
Args:
timeout (int | None): Timeout (in seconds) for command.
user (str | None): User to execute commands as.
Returns:
String with command output (stdout) or command error (stderr).
Expand All @@ -60,7 +64,9 @@ async def execute(code: str) -> str:
Returns:
The output of the command.
"""
result = await sandbox().exec(cmd=["python3"], input=code, timeout=timeout)
result = await sandbox().exec(
cmd=["python3"], input=code, timeout=timeout, user=user
)
if result.success:
return result.stdout
else:
Expand Down

0 comments on commit 5b7f186

Please sign in to comment.