Skip to content

Restrict code execution scope and enforce import whitelist#196

Merged
pancacake merged 1 commit intoHKUDS:devfrom
RinZ27:feat/code-executor-hardening
Feb 15, 2026
Merged

Restrict code execution scope and enforce import whitelist#196
pancacake merged 1 commit intoHKUDS:devfrom
RinZ27:feat/code-executor-hardening

Conversation

@RinZ27
Copy link
Copy Markdown
Contributor

@RinZ27 RinZ27 commented Feb 12, 2026

Noticed the code execution tool was letting LLM-generated scripts roam around the project root and access all environment variables. To fix this, I restricted the workspace to the user data directory and stripped sensitive keys from the environment before execution.

Enforcing a default whitelist for imports via ImportGuard ensures that only safe libraries like numpy or matplotlib are used, even if the caller forgets to specify constraints. I've also updated the solver and research pipelines to leverage these restricted settings by default.

Confirmed that core functionalities like plotting and calculations still work fine under these tighter constraints. This should stop any potential RCE from escaping the sandbox or exfiltrating API keys.

@RinZ27 RinZ27 changed the title Hardening code execution: import whitelisting and path restriction Feb 12, 2026
@RinZ27 RinZ27 force-pushed the feat/code-executor-hardening branch from 1619187 to 30326bc Compare February 12, 2026 12:31
@pancacake
Copy link
Copy Markdown
Collaborator

yea that's a good one. Thanks!

@pancacake pancacake merged commit d69c1ce into HKUDS:dev Feb 15, 2026
@RinZ27 RinZ27 deleted the feat/code-executor-hardening branch February 15, 2026 06:33
pancacake added a commit that referenced this pull request Mar 12, 2026
The eval version of code_executor.py removed DEFAULT_SAFE_IMPORTS
which is referenced by research_pipeline.py (from PR #196). Re-add
the constant and apply it as default when no whitelist is provided.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants