-
Notifications
You must be signed in to change notification settings - Fork 184
refactor(core): create the unsafe executor's temp directory with mkdtemp #600
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
Merged
kalenkevich
merged 2 commits into
google:main
from
adilburaksen:harden/mkdtemp-unsafe-local-executor
Aug 4, 2026
+40
−5
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import { | |
| } from '@google/adk'; | ||
| import {EventEmitter} from 'node:events'; | ||
| import * as os from 'node:os'; | ||
| import * as path from 'node:path'; | ||
| import {beforeEach, describe, expect, it, vi} from 'vitest'; | ||
|
|
||
| // Only `spawn` is mocked; it defaults to the real implementation (see | ||
|
|
@@ -90,6 +91,37 @@ describe('UnsafeLocalCodeExecutor', () => { | |
| expect(result.stderr).toBe(''); | ||
| }); | ||
|
|
||
| // The script runs with the temporary directory as its cwd, so it can report | ||
| // the name and mode the executor actually created. | ||
| it('creates a private, unpredictable temporary directory', async () => { | ||
| const params: ExecuteCodeParams = { | ||
| invocationContext, | ||
| codeExecutionInput: { | ||
| code: [ | ||
| 'const fs = require("node:fs");', | ||
| 'const dir = process.cwd();', | ||
| 'const mode = (fs.statSync(dir).mode & 0o777).toString(8);', | ||
| 'console.log(JSON.stringify({dir, mode}));', | ||
| ].join('\n'), | ||
| language: CodeExecutionLanguage.JAVASCRIPT, | ||
| inputFiles: [], | ||
| }, | ||
| }; | ||
|
|
||
| const first = JSON.parse((await executor.executeCode(params)).stdout); | ||
| const second = JSON.parse((await executor.executeCode(params)).stdout); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, optional. If either run fails, const first = JSON.parse((await executor.executeCode(params)).stdout);
const second = JSON.parse((await executor.executeCode(params)).stdout); const firstResult = await executor.executeCode(params);
const secondResult = await executor.executeCode(params);
expect(firstResult.stderr).toBe('');
expect(secondResult.stderr).toBe('');
const first = JSON.parse(firstResult.stdout);
const second = JSON.parse(secondResult.stdout);
|
||
|
|
||
| // mkdtemp appends six random characters to the prefix it is given. | ||
| expect(path.basename(first.dir)).toMatch( | ||
| /^adk_js_unsafe_code_executor_.{6}$/, | ||
| ); | ||
| expect(second.dir).not.toBe(first.dir); | ||
|
|
||
| if (os.platform() !== 'win32') { | ||
| expect(first.mode).toBe('700'); | ||
| } | ||
| }); | ||
|
|
||
| it('should capture stderr', async () => { | ||
| const params: ExecuteCodeParams = { | ||
| invocationContext, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. The comment narrates the old code rather than the new.
// mkdtemp names the directory itself and creates it exclusively at 0o700.Nothing else in
core/srcexplains a prior implementation (grepped — zero hits), and your PR description already covers the archaeology, which is where it survives a rename. Same shape as the doc-comment nit on #599, so treat it as one habit rather than two findings.