Skip to content

Localize sandbox thread quota enforcement to sandbox imports#195

Merged
seanwevans merged 1 commit intomainfrom
codex/refactor-thread-management-for-sandbox
Apr 21, 2026
Merged

Localize sandbox thread quota enforcement to sandbox imports#195
seanwevans merged 1 commit intomainfrom
codex/refactor-thread-management-for-sandbox

Conversation

@seanwevans
Copy link
Copy Markdown
Owner

Motivation

  • Prevent global mutation of threading.Thread.start which could affect non-sandbox host threads.
  • Keep child-thread quota/accounting enforced for sandboxed code while ensuring host threads remain untouched.

Description

  • Replace the global threading.Thread.start patch with a sandbox-scoped Thread subclass factory via _make_sandbox_thread_class that implements quota checks and accounting.
  • Return a wrapped threading module from _wrap_module(...) when sandboxed code imports threading, with Thread set to the sandbox-scoped class so only sandbox imports are affected.
  • Remove the global patch/unpatch operations from the sandbox run loop so non-sandbox threads are never modified.
  • Add a regression test test_sandbox_threading_patch_is_local_and_does_not_touch_global_start in tests/test_thread_extra.py to verify host threads run concurrently and that threading.Thread.start identity never changes globally.

Testing

  • Ran pytest -q tests/test_thread_extra.py tests/test_thread_quota.py, all tests passed: 13 passed.
  • The new regression test verifies no global behavior bleed while sandbox spawns threads and host threads continue using the original threading.Thread.start.

Codex Task

@seanwevans seanwevans merged commit 9261b9e into main Apr 21, 2026
9 of 19 checks passed
@seanwevans seanwevans deleted the codex/refactor-thread-management-for-sandbox branch April 21, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant