Skip to content

Conversation

@ArthurCRodrigues
Copy link

@ArthurCRodrigues ArthurCRodrigues commented Jan 23, 2026

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

There was a TODO at agent_engine_sandbox_code_executor.py:

Add TTL for sandbox creation after it is available in SDK.

  • Added sandbox_ttl: Optional[str] = None class attribute
  • Added sandbox_ttl parameter to the init method
  • Updated class and method docstrings to document the new parameter
  • Removed the TODO comment and implemented TTL support by passing ttl=sandbox_ttl to CreateAgentEngineSandboxConfig

If applicable, please follow the issue templates to provide as much detail as
possible.

Problem:

There was a TODO at agent_engine_sandbox_code_executor.py:

Add TTL for sandbox creation after it is available in SDK.

Solution:

Did the TODO :)

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed pytest results.

tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py::TestAgentEngineSandboxCodeExecutor::test_init_with_sandbox_overrides PASSED
tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py::TestAgentEngineSandboxCodeExecutor::test_init_with_sandbox_overrides_throws_error PASSED
tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py::TestAgentEngineSandboxCodeExecutor::test_init_with_agent_engine_overrides_throws_error PASSED
tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py::TestAgentEngineSandboxCodeExecutor::test_execute_code_success PASSED
tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py::TestAgentEngineSandboxCodeExecutor::test_init_with_agent_engine_resource_name_and_ttl PASSED
tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py::TestAgentEngineSandboxCodeExecutor::test_init_with_agent_engine_resource_name_without_ttl PASSED

============================== 6 passed in 6.28s ==============================

Manual End-to-End (E2E) Tests:

  1. Set up Vertex AI credentials:

    gcloud auth application-default login
  2. Create a sandbox with TTL:

    from google.adk.code_executors.agent_engine_sandbox_code_executor import AgentEngineSandboxCodeExecutor
    
    # Create executor with 1 hour TTL
    executor = AgentEngineSandboxCodeExecutor(
        agent_engine_resource_name="projects/<YOUR_PROJECT>/locations/us-central1/reasoningEngines/<YOUR_ENGINE_ID>",
        sandbox_ttl="3600s",  # 1 hour TTL
    )
    
    # Verify sandbox was created with TTL
    print(f"Sandbox created: {executor.sandbox_resource_name}")
    print(f"TTL set to: {executor.sandbox_ttl}")
  3. Verify the sandbox expires after the TTL period (or check in Vertex AI console)


Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Usage Example

from google.adk.code_executors.agent_engine_sandbox_code_executor import AgentEngineSandboxCodeExecutor

# Create a sandbox that expires after 1 hour
executor = AgentEngineSandboxCodeExecutor(
    agent_engine_resource_name="projects/my-project/locations/us-central1/reasoningEngines/123",
    sandbox_ttl="3600s",  # 1 hour
)

# Or create a sandbox without TTL (uses server default)
executor = AgentEngineSandboxCodeExecutor(
    agent_engine_resource_name="projects/my-project/locations/us-central1/reasoningEngines/123",
)

TTL Format

The TTL follows the Google Cloud duration format:

  • "3600s" - 1 hour
  • "86400s" - 1 day
  • "604800s" - 1 week

@google-cla
Copy link

google-cla bot commented Jan 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ArthurCRodrigues, 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 addresses a previously identified TODO by implementing Time-To-Live (TTL) functionality for sandboxes created by the AgentEngineSandboxCodeExecutor. This enhancement allows users to specify an expiration duration for sandboxes, ensuring automatic resource cleanup and better management of temporary environments.

Highlights

  • Sandbox TTL Parameter: Introduced sandbox_ttl as an optional parameter in the AgentEngineSandboxCodeExecutor's __init__ method and as a class attribute.
  • Docstring Updates: Updated class and method docstrings to clearly document the new sandbox_ttl parameter, its purpose, and expected format.
  • TTL Implementation: The sandbox_ttl value is now passed directly to the CreateAgentEngineSandboxConfig during sandbox creation, enabling automatic resource cleanup.
  • TODO Resolution: A long-standing @TODO comment regarding the addition of TTL support for sandbox creation has been removed, indicating successful implementation.
  • Sample Code Update: The agent.py sample file has been updated with a commented-out example demonstrating how to use the new sandbox_ttl parameter.
  • Unit Test Coverage: New unit tests have been added to verify the correct behavior of sandbox creation both with and without the sandbox_ttl parameter.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 adk-bot added the core [Component] This issue is related to the core interface and implementation label Jan 23, 2026
@adk-bot
Copy link
Collaborator

adk-bot commented Jan 23, 2026

Response from ADK Triaging Agent

Hello @ArthurCRodrigues, thank you for creating this PR!

This is a great feature enhancement. Could you please associate a GitHub issue with this PR? If there is no existing issue, could you please create one? This will help us to track the feature request.

Also, it looks like you haven't signed the Contributor License Agreement (CLA) yet. Please make sure to sign it so we can proceed with reviewing your contribution. You can find more information about the CLA in the "Before you begin" section of our contribution guidelines.

Thanks!

Copy link
Contributor

@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 successfully implements the TODO to add a Time-To-Live (TTL) for sandbox creation in AgentEngineSandboxCodeExecutor. The changes include adding a sandbox_ttl parameter to the initializer, updating the class and method docstrings, and passing the TTL value during sandbox creation. The implementation is supported by new unit tests that verify the behavior both with and without a TTL specified.

The code is well-structured and the changes are clear. I have one suggestion regarding the assignment of the sandbox_ttl attribute to improve consistency, but overall this is a solid contribution.

)
# @TODO - Add TTL for sandbox creation after it is available
# in SDK.
self.sandbox_ttl = sandbox_ttl
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The sandbox_ttl attribute is only set when a new sandbox is created (i.e., when agent_engine_resource_name is provided). If an executor is initialized with an existing sandbox_resource_name, the sandbox_ttl parameter is ignored and self.sandbox_ttl remains None. This could be confusing for a user who provides the sandbox_ttl parameter in that case.

To improve consistency and predictability, consider setting self.sandbox_ttl = sandbox_ttl unconditionally at the beginning of the __init__ method. This would ensure the attribute always reflects the value passed to the constructor, even though it's only used during creation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add TTL for sandbox creation in AgentEngineSandboxCodeExecutor

2 participants