Skip to content
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

Unsafe Code Execution in Code Interpreter Tool broken #146

Open
OliverRM opened this issue Dec 13, 2024 · 0 comments
Open

Unsafe Code Execution in Code Interpreter Tool broken #146

OliverRM opened this issue Dec 13, 2024 · 0 comments

Comments

@OliverRM
Copy link

The Code Interpreter Tool is described as follows:

Python3 code used to be interpreted in the Docker container. ALWAYS PRINT the final result and the output of the code

Based on this description, the generated Python code should use print() to display the results.

When running in Docker mode, the tool behaves as expected, returning the printed output from the console:

    def run_code_in_docker(self, code: str, libraries_used: List[str]) -> str:
        ... 
        return exec_result.output.decode("utf-8")

However, when running in safe mode, the tool instead attempts to use the value of a result variable as the output:

def run_code_unsafe(self, code: str, libraries_used: List[str]) -> str:
    ...
    return exec_locals.get("result", "No result variable found.")

This behavior is inconsistent with the tool’s description. When running in unsafe mode, the generated code does not assign a result variable, leading to the error:

No result variable found.

Temporary Workaround

To resolve this issue temporarily, I updated my coding agent’s goal with the following instruction:

It is important to return the results as a string variable. Printing them to the console will not be sufficient. Create a string variable called result containing all the results.

This ensures the generated code aligns with the requirements of the unsafe mode.

Proposed Solution

The tool should be updated to ensure consistency between Docker and safe modes. Specifically:

  • Either update the tool’s description to include the need for a result variable in unsafe mode, or
  • Modify the unsafe mode implementation to use printed output, aligning it with the Docker mode behavior.
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

No branches or pull requests

1 participant