Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
eca74d6
Add initial skill for testing, which is simply Steve's skill (#1)
donald-pinckney Feb 2, 2026
5998c64
Use claude to merge Steve's, Max's, and Mason's skills. (#2)
donald-pinckney Feb 4, 2026
ff033bc
add simple feedback mechanism (#3)
donald-pinckney Feb 4, 2026
b8b74c0
Change skill name to kebab-case, for compatibility with Amp and Cline…
donald-pinckney Feb 13, 2026
d25073a
Clean up references/core/ai-integration.md
donald-pinckney Feb 13, 2026
b0fcfe3
Clean up references/core/common-gotchas.md
donald-pinckney Feb 13, 2026
e113399
Clean up references/core/common-gotchas.md
donald-pinckney Feb 13, 2026
2b6676f
Clean up references/core/determinism.md
donald-pinckney Feb 13, 2026
efc8ef2
Clean up references/core/determinism.md
donald-pinckney Feb 13, 2026
45497f4
Update error-reference.md
donald-pinckney Feb 17, 2026
f61d2ea
Update interactive-workflows.md
donald-pinckney Feb 17, 2026
1f4c53d
Clean up patterns.md
donald-pinckney Feb 17, 2026
3c19991
Cut shell scripts
donald-pinckney Feb 17, 2026
d237247
Edit troubleshooting.md
donald-pinckney Feb 17, 2026
5695854
remove interceptors for now
donald-pinckney Feb 18, 2026
e10cbb8
remove dynamic workflows
donald-pinckney Feb 18, 2026
d4d9921
clarify on heartbeating of async activity completions, and prompt it …
donald-pinckney Feb 18, 2026
1c185b6
Improve references/python/advanced-features.md
donald-pinckney Feb 18, 2026
e945f1d
Use explicit namespace in connect
donald-pinckney Feb 18, 2026
322f85a
remove duplicated content from determinism.md, clean up
donald-pinckney Feb 18, 2026
bb46cb4
Improve references/python/data-handling.md
donald-pinckney Feb 18, 2026
3dcccb8
Prefer start_to_close_timeout
donald-pinckney Feb 18, 2026
8b7dffa
don't explicitely provide defaults for retry policies
donald-pinckney Feb 18, 2026
f693cc7
error-handling.md cleanup
donald-pinckney Feb 18, 2026
3d43cd2
move idempotency patterns to patterns.md
donald-pinckney Feb 18, 2026
f0387e3
remove multi-param activities
donald-pinckney Feb 18, 2026
f36faca
small edits
donald-pinckney Feb 18, 2026
0bc69b2
Unify sandbox stuff into one file
donald-pinckney Feb 18, 2026
56dde75
local activities aren't experimental
donald-pinckney Feb 18, 2026
35c3bc5
Clean up references/python/sync-vs-async.md
donald-pinckney Feb 18, 2026
d61866b
Cleanup observability.md, remove duplicated search attributes
donald-pinckney Feb 19, 2026
ad4cc34
Cut otel for now
donald-pinckney Feb 19, 2026
f01763a
cut a lot of duplicate stuff from python gotchas, address comments
donald-pinckney Feb 20, 2026
cbfd857
de-duplicate content
donald-pinckney Feb 20, 2026
79ecaf3
Lots of improvements to testing
donald-pinckney Feb 20, 2026
663bbe4
cleanup to top level of skill (like CLI install instructions), and to…
donald-pinckney Feb 20, 2026
ec02f38
Improve patterns.md
donald-pinckney Feb 23, 2026
14da16a
clean up ai-patterns.md
donald-pinckney Feb 23, 2026
fd1af23
Update readme with installation instructions
donald-pinckney Feb 23, 2026
846cb44
remove ts directory
donald-pinckney Feb 23, 2026
0692311
De-couple core from python and TypeScript as much as possible
donald-pinckney Feb 23, 2026
83aa233
Remove TypeScript hints
donald-pinckney Feb 23, 2026
47ae2fd
add prompting for feedback at startup - wait for ethan on slack channel
donald-pinckney Feb 19, 2026
75c568d
shorten url
donald-pinckney Feb 19, 2026
3f972f9
Update slack channel
donald-pinckney Feb 23, 2026
99a2d4a
Automated pass over on python cleanup & deduplication
donald-pinckney Feb 27, 2026
87fe92e
Remove multi-patching from Python, since its obvious, dont waste toke…
donald-pinckney Mar 3, 2026
766f888
Add TypeScript (#31)
donald-pinckney Mar 7, 2026
8ad9233
Fix typos and reference links (#36)
donald-pinckney Mar 7, 2026
c73c9c0
quick edit to readme (#37)
donald-pinckney Mar 12, 2026
c013b87
Fix saga compensations to run under cancellation protection (#43)
donald-pinckney Mar 17, 2026
291f4e5
Update readme for public preview (#45)
donald-pinckney Mar 18, 2026
21d1d41
a few more readme tweaks (#46)
donald-pinckney Mar 18, 2026
6cd40f2
Add MIT License to the project (#47)
donald-pinckney Mar 18, 2026
e16c9b8
Add Go (supersedes other PR) (#38)
donald-pinckney Mar 19, 2026
b9a0728
Setup CODEOWNERS to AI SDK team (#48)
donald-pinckney Mar 19, 2026
29e4600
Align version number in SKILL.md and plugin.json. (#49)
donald-pinckney Mar 19, 2026
1cc4591
Merge branch 'main' into dev
donald-pinckney Mar 19, 2026
68ebe14
Fix typos and broken references across skill docs (#56)
jacksonlo Mar 31, 2026
b040ae1
Fix Python reference bugs: incorrect API name, syntax error, broken c…
trevoryao Mar 31, 2026
57c08ef
Add `@workflow.init` decorator to python.md Key Concepts (#57)
brianstrauch Mar 31, 2026
8369c65
Remove ASCII diagram, replace with prose. (#66)
donald-pinckney Apr 2, 2026
9b97cee
[fix] Add missing section to TS's observability (#65)
donald-pinckney Apr 2, 2026
0c8586b
Add Java SDK support (#42)
donald-pinckney Apr 2, 2026
7d5ae76
Reduce repetition in determinism sans sandboxing (#67)
donald-pinckney Apr 2, 2026
25eb553
Bump to 0.2.0 for Java release (#72)
donald-pinckney Apr 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve references/python/advanced-features.md
  • Loading branch information
donald-pinckney committed Feb 19, 2026
commit 1c185b645545c1f48d003158a0bf188b9d07d287
150 changes: 137 additions & 13 deletions references/python/advanced-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ async def complete_approval(request_id: str, approved: bool):

## Sandbox Customization

The Python SDK runs workflows in a sandbox to ensure determinism. You can customize sandbox restrictions when needed.
The Python SDK runs workflows in a sandbox to help you ensure determinism. You can customize sandbox restrictions when needed.

### Passing Through Modules

If you need to use modules that are blocked by the sandbox:
For performance and behavior reasons, you are encouraged to pass through all modules whose calls will be deterministic.

```python
from temporalio.worker import Worker
Expand All @@ -194,27 +194,132 @@ worker = Worker(
restrictions = SandboxRestrictions.default.with_passthrough_all_modules()
```

### Temporary Passthrough in Workflow Code
### Temporary Passthrough Context Manager

```python
from temporalio import workflow
from datetime import timedelta

# Mark imports inside this block as passthrough
with workflow.unsafe.imports_passed_through():
from activities import say_hello # your activity
import pydantic # or other deterministic third‑party libs

@workflow.run
async def run(self) -> str:
# Temporarily disable sandbox restrictions for imports
with workflow.unsafe.imports_passed_through():
import some_restricted_module
# Use the module...
# ... use the imports here
```

**Note:** The imports, even when using `imports_passed_through`, should all be at the top of the file. Runtime imports are an anti-pattern.

### Temporary Unrestricted Sandbox

```python
from temporalio import workflow

@workflow.defn
class MyWorkflow:
@workflow.run
async def run(self) -> None:
# Normal sandboxed code here

with workflow.unsafe.sandbox_unrestricted():
# Code here runs without sandbox restrictions
# e.g., a restricted os/path call or special logging
do_something_non_sandbox_safe()
```

- Per‑block escape hatch from runtime restrictions; imports unchanged.
- Use when: You need to call something the sandbox would normally block (e.g., a restricted stdlib call) in a very small, controlled section.
- **IMPORTANT:** Use it sparingly; you lose determinism checks inside the block
- Genuinely non-deterministic code still *MUST* go into activities.


### Customizing Invalid Module Members

`invalid_module_members` includes modules that cannot be accessed.

Checks are compared against the fully qualified path to the item.

```python
import dataclasses
from temporalio.worker import Worker
from temporalio.worker.workflow_sandbox import (
SandboxedWorkflowRunner,
SandboxMatcher,
SandboxRestrictions,
)

# Example 1: Remove a restriction on datetime.date.today():
restrictions = dataclasses.replace(
SandboxRestrictions.default,
invalid_module_members=SandboxRestrictions.invalid_module_members_default.with_child_unrestricted(
"datetime", "date", "today",
),
)

# Example 2: Restrict the datetime.date class from being used
restrictions = dataclasses.replace(
SandboxRestrictions.default,
invalid_module_members=SandboxRestrictions.invalid_module_members_default | SandboxMatcher(
children={"datetime": SandboxMatcher(use={"date"})},
),
)
```

### Import Notification Policy

Control warnings/errors for sandbox import issues. Recommended for catching potential problems:

```python
from temporalio import workflow
from temporalio.worker.workflow_sandbox import SandboxedWorkflowRunner, SandboxRestrictions

restrictions = SandboxRestrictions.default.with_import_notification_policy(
workflow.SandboxImportNotificationPolicy.WARN_ON_DYNAMIC_IMPORT
| workflow.SandboxImportNotificationPolicy.WARN_ON_UNINTENTIONAL_PASSTHROUGH
)

worker = Worker(
...,
workflow_runner=SandboxedWorkflowRunner(restrictions=restrictions),
)
```

- `WARN_ON_DYNAMIC_IMPORT` (default) - warns on imports after initial workflow load
- `WARN_ON_UNINTENTIONAL_PASSTHROUGH` - warns when modules are imported into sandbox without explicit passthrough (not default, but highly recommended for catching missing passthroughs)
- `RAISE_ON_UNINTENTIONAL_PASSTHROUGH` - raise instead of warn

Override per-import with the context manager:

```python
# Allow specific members that are normally blocked
restrictions = SandboxRestrictions.default
restrictions = restrictions.with_invalid_module_member_children(
"datetime", {"datetime": {"now"}} # Block datetime.datetime.now
with workflow.unsafe.sandbox_import_notification_policy(
workflow.SandboxImportNotificationPolicy.SILENT
):
import pydantic # No warning for this import
```

### Disable Lazy sys.modules Passthrough

By default, passthrough modules are lazily added to the sandbox's `sys.modules` when accessed. To require explicit imports:

```python
import dataclasses
from temporalio.worker.workflow_sandbox import SandboxedWorkflowRunner, SandboxRestrictions

restrictions = dataclasses.replace(
SandboxRestrictions.default,
disable_lazy_sys_module_passthrough=True,
)

worker = Worker(
...,
workflow_runner=SandboxedWorkflowRunner(restrictions=restrictions),
)
```

When `True`, passthrough modules must be explicitly imported to appear in the sandbox's `sys.modules`.

## Gevent Compatibility Warning

**The Python SDK is NOT compatible with gevent.** Gevent's monkey patching modifies Python's asyncio event loop in ways that break the SDK's deterministic execution model.
Expand Down Expand Up @@ -249,7 +354,9 @@ worker = Worker(

## Workflow Init Decorator

Use `@workflow.init` to run initialization code when a workflow is first created (not on replay).
Use `@workflow.init` to run initialization code when a workflow is first created.

**Purpose:** Execute some setup code before signal/update happens or run is invoked.

```python
@workflow.defn
Expand All @@ -268,7 +375,12 @@ class MyWorkflow:

## Workflow Failure Exception Types

Control which exceptions cause workflow task failures vs workflow failures:
Control which exceptions cause workflow task failures vs workflow failures.

- Special case: if you include temporalio.workflow.NondeterminismError (or a superclass), non-determinism errors will fail the workflow instead of leaving it in a retrying state
- **Tip for testing:** Set to `[Exception]` in tests so any unhandled exception fails the workflow immediately rather than retrying the workflow task forever. This surfaces bugs faster.

### Per-Workflow Configuration

```python
@workflow.defn(
Expand All @@ -280,3 +392,15 @@ class MyWorkflow:
async def run(self) -> str:
raise ValueError("This fails the workflow, not just the task")
```

### Worker-Level Configuration

```python
worker = Worker(
client,
task_queue="my-queue",
workflows=[MyWorkflow],
workflow_failure_exception_types=[ValueError, CustomBusinessError],
)
```