Skip to content

Restrict time.clock_gettime and clock_gettime_ns in the workflow sandbox - #2055

Open
Jackmeson1 wants to merge 1 commit into
temporalio:mainfrom
Jackmeson1:fix/sandbox-clock-gettime
Open

Jackmeson1 wants to merge 1 commit into
temporalio:mainfrom
Jackmeson1:fix/sandbox-clock-gettime

Conversation

@Jackmeson1

Copy link
Copy Markdown

What was changed

Adds clock_gettime and clock_gettime_ns to the default workflow sandbox's runtime-only time restrictions. Calling either through the sandbox now raises RestrictedWorkflowAccessError; importing or referencing them and calling them during workflow-module import remain allowed.

Why?

The existing restrictions block clock readers such as time, monotonic and process_time, but omit these two functions. On 01af1f6, both can read CLOCK_REALTIME from a sandboxed workflow without raising.

This tightens the default restrictions: with default failure handling, an uncaught violation fails the workflow task. Only these two names are added; argument-dependent time functions remain outside this change. The sandbox remains best effort, as documented in the README. No replay divergence was reproduced.

Checklist

  1. Related: none. This is a narrow fix to the sandbox restriction list.

  2. How was this tested:

    Outside-sandbox validation on Linux x86_64 (Colab), using the Rust bridge built from this checkout and pytest 9.1.1:

    • The importer test covers time, monotonic, clock_gettime and clock_gettime_ns. Each call succeeds before the runtime transition and then must raise RestrictedWorkflowAccessError with the expected qualified name. Missing functions are skipped.
    • The existing worker-backed restriction test gets both CLOCK_REALTIME calls, guarded by platform availability. Its workflow converts restriction errors to ApplicationError so the test can assert the resulting workflow failure.
    • Against 01af1f6, both new clock cases fail with DID NOT RAISE RestrictedWorkflowAccessError, and the worker test fails with DID NOT RAISE WorkflowFailureError; the two existing-clock controls pass. Adding only one name leaves two failures.
    • I ran pytest tests/worker/workflow_sandbox: 35 passed, 1 skipped on 01af1f6; 39 passed, 1 skipped with the fix on Python 3.13.16 and 3.14.8; 40 passed on 3.10.22. I also ran time-skipping V2 on 3.13.16: 39 passed, 1 skipped.
    • I ran the full suite, pytest -n 4 --dist=worksteal, on Python 3.13.16: 1549 passed, 5 skipped on 01af1f6; 1553 passed, 5 skipped with the fix. The saved JUnit reports show four added cases and no changed statuses among existing tests.
    • I ran poe lint, which passed with ruff 0.15.22, pyright 1.1.403, mypy 1.18.2, basedpyright 1.34.0 and pydocstyle 6.3.0.
    • Windows/macOS target checks passed on the three changed Python files: pyright and basedpyright for Windows Python 3.10/3.14 and Darwin 3.14; mypy for win32 and darwin. These checks ran on Linux; Windows, macOS and ARM execution were not tested.
  3. Any docs updates needed?

    Added changelog/breaking-changes/punctual-platypus.md. The README documents the general restriction behavior and best-effort limitation.

AI disclosure: this was prepared with AI assistance (Claude Opus 5.5).

🤖 Generated with Claude Code

The runtime-only restrictions on the time module block time(),
monotonic(), perf_counter(), process_time() and the other clock readers,
but not clock_gettime() or clock_gettime_ns(), so workflow code could
read the clocks through them without the sandbox raising. Add both to
the restricted set. Calls while the workflow module is imported stay
allowed, as for the other time entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TTGAv6fe859ebbCLLfLHP
Signed-off-by: Jackmeson1 <130693642+Jackmeson1@users.noreply.github.com>
@Jackmeson1
Jackmeson1 requested a review from a team as a code owner October 31, 2026 06:31

This branch has not been deployed

No deployments
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.

1 participant