Skip to content

Conversation

@VegetarianOrc
Copy link
Contributor

@VegetarianOrc VegetarianOrc commented Oct 24, 2025

What was changed

  • Added new temporalio.worfklow.SandboxImportNotificationPolicy enum.
  • Added new SandboxRestrictions.import_notification_policy setting to control the notification policy for imports processed by the sandbox.
  • Add new context manager and accessor to workflow.unsafe to allow overriding the SandboxImportNotificationPolicy set on the configured SandboxRestritions.
  • Added new RestrictionContext.in_activation field to indicate if the sandbox is handling an activation so we can differentiate between workflow load time.
  • Updated _Importer to respect the override and configured policy to:
    1. Warn if an import occurred during activation.
    2. Warn if an import occurs that was not intentionally passed through to the sandbox.
    3. Raise an error if an import occurs that was not intentionally passed through to the sandbox.
  • Updated SandboxRestrictions.default to use SandboxImportNotificationPolicy.WARN_ON_DYNAMIC_IMPORT
  • Added a few combinations of SandboxImportNotificationPolicy flags to SandboxRestrictions for ease of use.

Why?

The introduction of the new import notification policy aims to tackle two challenges SDK users face that are described in #790. The new behaviors can be combined to provide the desired level of verbosity.

Increase Visibility into Dynamically Imported Modules

Some libraries will import modules as needed or as a result of a function call. In these cases, it may not be obvious to users that this is occurring and can cause unnecessary memory overhead. This new default setting will warn any time an import occurs during workflow task execution. Users may opt out of this warning by configuring the SandboxRunner with a SandboxImportNotificationPolicy or by using the context manager workflow.unsafe.sandbox_import_notification_policy.

Increase Discoverability of Modules Requiring Passthrough

Some users prefer to ensure that imports used by the sandbox are explicitly passed through. The new opt-in settings of SandboxImportNotificationPolicy.WARN_ON_UNINTENTIONAL_PASSTHROUGH and SandboxImportNotificationPolicy.RAISE_ON_UNINTENTIONAL_PASSTHROUGH allow users to discover any import that occurs in the sandbox that is not explicitly passed through. These settings are mutually exclusive and if both are set on the import notification policy, RAISE_ON_UNINTENTIONAL_PASSTHROUGH will be respected. Users may opt into this behavior by configuring the SandboxRunner with a SandboxImportNotificationPolicy or by using the context manager workflow.unsafe.sandbox_import_notification_policy.

Checklist

Closes #790

How was this tested:

New tests were added to exercise a variety of policy combinations and verify that code run in an interceptor will also respect the new setting.

Any docs updates needed?

  • The Python SDK sandbox docs should be updated with information about the new default warning, other options, and examples of how to adjust the setting.

@VegetarianOrc VegetarianOrc marked this pull request as ready for review October 24, 2025 23:32
@VegetarianOrc VegetarianOrc requested a review from a team as a code owner October 24, 2025 23:32
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.

[Feature Request] Helpers to prevent accidental non-passed-through imports

1 participant