You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add sandbox import notification policy documentation
* Update docs/develop/python/python-sdk-sandbox.mdx
Co-authored-by: Jwahir Sundai <[email protected]>
* Update example to use both warning types instead of using the same option twice
---------
Co-authored-by: Jwahir Sundai <[email protected]>
Copy file name to clipboardExpand all lines: docs/develop/python/python-sdk-sandbox.mdx
+51-1Lines changed: 51 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,10 +100,11 @@ To skip a sandbox environment for a Worker, set the `workflow_runner` keyword a
100
100
When creating the Worker, the `workflow_runner` defaults to [`SandboxedWorkflowRunner()`](https://python.temporal.io/temporalio.worker.workflow_sandbox.SandboxedWorkflowRunner.html).
101
101
The `SandboxedWorkflowRunner` init accepts a `restrictions` keyword argument that defines a set of restrictions to apply to this sandbox.
102
102
103
-
The [`SandboxRestrictions`](https://python.temporal.io/temporalio.worker.workflow_sandbox.SandboxRestrictions.html) dataclass is immutable and contains three fields that can be customized, but only two have notable values.
103
+
The [`SandboxRestrictions`](https://python.temporal.io/temporalio.worker.workflow_sandbox.SandboxRestrictions.html) dataclass is immutable and contains four fields that can be customized, but only three have notable values.
The sandbox's import notification policy specifies how the sandbox behaves when it imports modules in a way that may be unintentional. It covers two common scenarios: dynamic imports and enforcing module passthrough. Each can be controlled independently.
202
+
203
+
A dynamic import occurs when a module is imported after the Workflow is loaded into the sandbox. These imports are often invisible and, if they don't do anything restricted by the sandbox, cause memory overhead. By default the [`WARN_ON_DYNAMIC_IMPORT`](https://python.temporal.io/temporalio.workflow.SandboxImportNotificationPolicy.html#WARN_ON_DYNAMIC_IMPORT) policy setting is enabled and a warning will be emitted when one of these imports occurs.
204
+
205
+
The other notable policy settings apply when a module is imported into the sandbox that was not passed through. These settings are disabled by default and must be explicitly turned on.
206
+
The [`WARN_ON_UNINTENTIONAL_PASSTHROUGH`](https://python.temporal.io/temporalio.workflow.SandboxImportNotificationPolicy.html#WARN_ON_UNINTENTIONAL_PASSTHROUGH) setting emits a warning when a module not included in the [passthrough modules](#passthrough-modules) list.
207
+
208
+
Similarly, the [`RAISE_ON_UNINTENTIONAL_PASSTHROUGH`](https://python.temporal.io/temporalio.workflow.SandboxImportNotificationPolicy.html#RAISE_ON_UNINTENTIONAL_PASSTHROUGH) setting will raise an error when an non-passed-through module is imported.
209
+
210
+
The import notification policy can be set for specific imports by using [`sandbox_import_notification_policy`](https://python.temporal.io/temporalio.workflow.unsafe.html#sandbox_import_notification_policy) context manager.
211
+
212
+
```python
213
+
# my_workflow_file.py
214
+
215
+
from temporalio import workflow
216
+
217
+
with workflow.unsafe.sandbox_import_notification_policy(
218
+
workflow.SandboxImportNotificationPolicy.SILENT
219
+
):
220
+
import pydantic
221
+
222
+
@workflow.defn
223
+
classMyWorkflow:
224
+
# ...
225
+
```
226
+
227
+
This can also be done at worker creation time by customizing the runner's restrictions.
228
+
229
+
```python
230
+
# my_worker_file.py
231
+
232
+
from temporalio.worker import Worker
233
+
from temporalio.worker.workflow_sandbox import SandboxedWorkflowRunner, SandboxRestrictions
The [`sandbox_import_notification_policy`](https://python.temporal.io/temporalio.workflow.unsafe.html#sandbox_import_notification_policy) context manager will always be respected if used in combination with the restrictions customization.
246
+
247
+
198
248
For more information on the Python sandbox, see the following resources.
0 commit comments