Skip to content

feat: unsafe local code executor#257

Open
kalenkevich wants to merge 1 commit intomainfrom
feat/unsafe_local_code_executor
Open

feat: unsafe local code executor#257
kalenkevich wants to merge 1 commit intomainfrom
feat/unsafe_local_code_executor

Conversation

@kalenkevich
Copy link
Copy Markdown
Collaborator

Link to Issue or Description of Change

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

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

Problem:
The ADK lacked a concrete implementation for executing code locally in a Node.js environment. While BaseCodeExecutor provided the structure, there was no ready-to-use executor for running JavaScript or TypeScript code blocks locally. Additionally, BaseCodeExecutor was missing default delimiters for javascript and typescript code blocks.

Solution:

  1. Implemented UnsafeLocalCodeExecutor in core/src/code_executors/unsafe_local_code_executor.ts. This executor:
    • Writes the provided code to a temporary .js file.
    • Spawns a child process using Node.js (by default) to execute the file.
    • Captures stdout and stderr.
    • Supports a configurable timeout to prevent hanging executions (defaults to 30s).
    • Cleans up the temporary file after execution.
  2. Updated BaseCodeExecutor in core/src/code_executors/base_code_executor.ts to include javascript and typescript in codeBlockDelimiters and updated documentation examples to use JavaScript.
  3. Exported UnsafeLocalCodeExecutor from core/src/index.ts.
  4. Added Unit Tests:
    • core/test/code_executors/base_code_executor_test.ts to verify default values and type guards.
    • core/test/code_executors/unsafe_local_code_executor_test.ts to verify code execution, stderr capture, and timeout behavior.

Testing Plan

Unit Tests:

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

Manual End-to-End (E2E) Tests:
No manual E2E tests were performed as the unit tests cover the execution logic by spawning actual Node.js processes.

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.

@kalenkevich kalenkevich self-assigned this Apr 10, 2026
@kalenkevich kalenkevich force-pushed the feat/unsafe_local_code_executor branch from 944b00d to 9fccda9 Compare April 10, 2026 03:26
@kalenkevich kalenkevich force-pushed the feat/unsafe_local_code_executor branch from 9fccda9 to 5fa5c2e Compare April 10, 2026 18:27
@kalenkevich kalenkevich force-pushed the feat/unsafe_local_code_executor branch from 5fa5c2e to 33eb2b2 Compare April 10, 2026 18:28
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

Successfully merging this pull request may close these issues.

2 participants