Skip to content

Conversation

AlexFierro9
Copy link

@AlexFierro9 AlexFierro9 commented Oct 20, 2025

Have added a new Isolated Code Executor that uses subprocesses module to run the code on a new interpreter process, there is a bonus of isolated code execution for local setups as well. Working on support for Docker Integration as well but that is going to be a while.

Implements feature plan partly described in #3075

@gemini-code-assist
Copy link

Summary of Changes

Hello @AlexFierro9, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new IsolatedCodeExecutor designed to enhance code execution safety and isolation. By utilizing Python's subprocess module, it runs code in a separate interpreter process, effectively sandboxing the execution. This approach is particularly beneficial for local development environments, preventing potential conflicts or crashes from affecting the main application. Future enhancements are planned to extend this isolation to Docker environments.

Highlights

  • New Isolated Code Executor: A new IsolatedCodeExecutor class has been introduced to provide a mechanism for executing code in an isolated environment.
  • Subprocess-based Execution: This executor leverages Python's subprocess module to run code in a new interpreter process, ensuring isolation from the main application.
  • Local Setup Isolation: The current implementation primarily focuses on providing isolated code execution for local development and testing setups.
  • Executor Configuration: The IsolatedCodeExecutor is explicitly designed to be non-stateful and does not support data file optimization, with checks in place to prevent these configurations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot
Copy link
Collaborator

adk-bot commented Oct 20, 2025

Response from ADK Triaging Agent

Hello @AlexFierro9, thank you for creating this PR!

To help us review your contribution, could you please address the following points from our contribution guidelines:

  • Associated Issue: For new features like this, an associated GitHub issue is required. If one doesn't exist, please create one and link it to this PR.
  • Testing Plan: Please add a testing plan section to your PR description explaining how you've tested these changes.

This information will help reviewers to review your PR more efficiently. Thanks!

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an IsolatedCodeExecutor that runs code in a separate process using subprocess, which is a good improvement for isolation. My review includes several suggestions to enhance security and robustness, such as adding a timeout to prevent denial-of-service attacks and clarifying the security guarantees in the docstring. I've also pointed out some code cleanup opportunities like removing unused imports and dead code.

@AlexFierro9
Copy link
Author

#3075

AlexFierro9 and others added 2 commits October 20, 2025 11:40
Unused imports can be confusing

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@adk-bot
Copy link
Collaborator

adk-bot commented Oct 20, 2025

Response from ADK Triaging Agent

Hello @AlexFierro9, thank you for creating this PR and for linking the issue!

To help us review your contribution, could you please also add a testing plan section to your PR description explaining how you've tested these changes as requested in our contribution guidelines?

This information will help reviewers to review your PR more efficiently. Thanks!

@AlexFierro9
Copy link
Author

Implemented unit-tests in line with those from unsafe local code executor

@AlexFierro9
Copy link
Author

@boyangsvl please assign a reviewer as time permits

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new IsolatedCodeExecutor that enhances code execution security by running code in a separate process. This approach provides memory isolation, preventing the executed code from directly interfering with the main application. The changes include the implementation of the executor and corresponding unit tests to ensure its functionality and robustness. The executor is designed to be stateless and not optimize data files, with appropriate checks in place to prevent these features from being enabled.

Comment on lines +48 to +52
process_result = subprocess.run(
[sys.executable, "-c", code],
capture_output=True,
text=True
)

Choose a reason for hiding this comment

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

high

Consider adding a timeout to the subprocess.run call to prevent indefinite hanging in case the executed code enters an infinite loop or takes too long to execute. This will improve the robustness of the executor.

Also, it might be useful to capture and log the return code of the subprocess for debugging purposes.

    process_result = subprocess.run(
    [sys.executable, "-c", code],
    capture_output=True,
    text=True, # Enables decoding of stdout and stderr as text
    timeout=30 # Add a timeout to prevent indefinite hanging
    )

    if process_result.returncode != 0:
      print(f"Code execution failed with return code: {process_result.returncode}")

Comment on lines +55 to +58
return CodeExecutionResult(
stdout=process_result.stdout,
stderr=process_result.stderr,
output_files=[],

Choose a reason for hiding this comment

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

medium

It's important to handle potential exceptions that might occur during the code execution within the subprocess. For example, the code might raise an exception that isn't properly propagated back to the main process. Consider adding a try-except block around the subprocess.run call to catch and handle such exceptions, providing more informative error messages in the CodeExecutionResult.

Suggested change
return CodeExecutionResult(
stdout=process_result.stdout,
stderr=process_result.stderr,
output_files=[],
try:
process_result = subprocess.run(
[sys.executable, "-c", code],
capture_output=True,
text=True
)
except subprocess.TimeoutExpired as e:
return CodeExecutionResult(
stdout="",
stderr=f"Code execution timed out: {e}",
output_files=[],
)
except Exception as e:
return CodeExecutionResult(
stdout="",
stderr=f"Code execution failed: {e}",
output_files=[],
)


assert isinstance(result, CodeExecutionResult)
assert result.stdout == ""
assert "Test error" in result.stderr

Choose a reason for hiding this comment

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

medium

The test asserts that "Test error" is in result.stderr. It would be more robust to assert that the ValueError exception type is also present in the stderr. This ensures that the correct exception is being raised and captured.

Suggested change
assert "Test error" in result.stderr
assert "ValueError" in result.stderr
assert "Test error" in result.stderr

@ryanaiagent ryanaiagent self-assigned this Oct 20, 2025
@ryanaiagent ryanaiagent added the tools [Component] This issue is related to tools label Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants