Expression evaluation
Elsa represents workflow values as typed expressions and evaluates them in the context of a running workflow activity. The same contract supports simple values and four language-based evaluators: C#, JavaScript, Liquid, and Python. For the wider authoring model, read Authoring and expressions; for workflow notation, read Workflow DSL and BPMN; for activity execution, read Workflow and activity execution.
Expression abstraction
Expression values
An Expression pairs a type name with a value. The type name selects the evaluator or value handler, while the value carries the literal data, script text, or workflow reference to resolve. This lets an activity store an input without knowing which expression language will produce it.
The built-in value forms include literal values, objects, workflow inputs, variables, activity outputs, and delegates. Language expressions use the names CSharp, JavaScript, Liquid, and Python when they are serialized in a workflow definition.
References: src/…/Expression.cs• L8-44 src/…/DefaultExpressionDescriptorProvider.cs• L17-25
Expression execution context
An ExpressionExecutionContext is the bridge between an evaluator and workflow state. It provides scoped services, shared memory, transient data, cancellation, and an optional parent context so an expression can resolve values from its activity and its enclosing scopes.
The context exposes workflow inputs, variables, activity outputs, and the current workflow or activity context through helper operations. An evaluator can also receive extra arguments for one evaluation through ExpressionEvaluatorOptions.
References: src/…/ExpressionExecutionContext.cs• L9-40 src/…/ExpressionExecutionContextExtensions.cs• L67-148 src/…/ExpressionExecutionContextExtensions.cs• L410-470 src/…/ExpressionEvaluatorOptions.cs• L6-16
Evaluation pipeline
Evaluator dispatch
The shared IExpressionEvaluator is the entry point for expression evaluation. It looks up the descriptor for the expression type, creates that type's handler, and passes the expression, expected result type, context, and options to the handler.
This separation keeps workflow activities independent from language engines. A handler converts the stored expression value into the form needed by its language service, then converts the result to the type requested by the activity.
This diagram shows how an activity input moves from its stored expression to a typed value.
flowchart LR
A[Activity input] --> B[Expression]
B --> C[Expression descriptor registry]
C --> D[Language or value handler]
D --> E[Expression execution context]
D --> F[Typed result]
F --> A
References: src/…/IExpressionEvaluator.cs• L8-28 src/…/ExpressionEvaluator.cs• L7-27 src/…/IExpressionHandler.cs• L8-18 src/…/ExpressionEvaluatorExtensions.cs• L13-29
Descriptor registry
An ExpressionDescriptor describes one expression type and connects it to its handler. It also tells authoring tools whether the type is visible and serializable. A descriptor can provide editor metadata and custom deserialization when the stored value needs to become a workflow object.
The registry gathers descriptors from all registered IExpressionDescriptorProvider services. The default provider adds the core value forms. Language features add their own descriptors, so installing a feature makes its language available to the common evaluator and to authoring tools.
References: src/…/ExpressionDescriptor.cs• L10-68 src/…/ExpressionDescriptorRegistry.cs• L7-43 src/…/DefaultExpressionDescriptorProvider.cs• L104-133 src/…/IExpressionDescriptorProvider.cs• L8-13
Expression languages
C# expressions
C# expressions provide general host-side scripting for trusted workflow authors. The C# feature evaluates the script with workflow context access and supports host configuration for script references, namespaces, and added script or option rules.
C# host-code execution is disabled by default. Roslyn scripting is not a sandbox, so a host must enable it only when workflow authors are trusted. The C# descriptor is browsable only when this capability is enabled.
During evaluation, the C# feature adds a workflow-variable proxy to the script. Variables with valid code names are available as properties, while all variables remain available through generic get and set operations. ExpandoObject variables use dynamic access, and the older Variables name remains an alias for Variable.
The Run C# activity uses the same C# service for a full script step. It stores a non-null result as the activity result and completes with the outcome selected by the script, or Done when no outcome is selected.
References: src/…/CSharpEvaluator.cs• L23-57 src/…/GenerateWorkflowVariableAccessors.cs• L19-64 src/…/CSharpExpressionDescriptorProvider.cs• L11-25 src/…/CSharpFeature.cs• L22-56 src/…/RunCSharp.cs• L32-73
JavaScript expressions
JavaScript expressions provide an embedded script language for workflow values and script activities. The evaluator prepares each distinct script for reuse, exposes only the workflow data that the script references, and converts the result back to the requested workflow type.
The JavaScript feature adds editor metadata and type definitions for workflow inputs, variables, common functions, and activity outputs. The engine supports execution limits, cancellation, and awaited asynchronous results. CLR arrays cross the boundary as copies by default, so script mutation does not change workflow data; hosts can opt into live views. CLR enum values appear by member name, which keeps script comparisons consistent with named workflow values. Access to .NET classes and application configuration is opt-in because those capabilities can cross the workflow boundary into the host process.
Jint now owns array-like collection detection. The older object-array helper remains only as an obsolete compatibility type and is not part of the active evaluation path.
The JavaScript feature also protects the editor's JavaScript type-definition service with a dedicated view permission. The service supplies workflow-specific TypeScript definitions for Monaco IntelliSense, so an editor caller without that permission cannot load those definitions.
The Run JavaScript activity uses the JavaScript service directly. Its script can return a value and can select one or more workflow outcomes through the activity's scripting interface.
References: src/…/JintJavaScriptEvaluator.cs• L24-45 src/…/JintJavaScriptEvaluator.cs• L48-84 src/…/JintJavaScriptEvaluator.cs• L87-139 src/…/JintJavaScriptEvaluator.cs• L142-179 src/…/ObjectArrayHelper.cs• L5-9 src/…/JavaScriptExpressionSyntaxProvider.cs• L11-24 src/…/JintOptions.cs• L22-83 src/…/JavaScriptFeature.cs• L28-47 src/…/Endpoint.cs• L31-54 src/…/JavaScriptPermissions.cs• L11-25 src/…/RunJavaScript.cs• L31-84
Liquid expressions
Liquid expressions render text templates rather than run general-purpose code. The template receives the expression context and registered filters, then returns rendered text that the workflow converts to the input's expected type.
The Liquid feature registers the template service and the Liquid expression descriptor. It also provides standard filters and supports application-defined filters or tags. Configuration access is an explicit host choice and must not be enabled for untrusted workflow content.
References: src/…/LiquidTemplateManager.cs• L14-44 src/…/LiquidExpressionHandler.cs• L11-29 src/…/LiquidExpressionSyntaxProvider.cs• L12-29 src/…/LiquidFeature.cs• L22-56 src/…/DependencyInjectionExtensions.cs• L10-36
Python expressions
Python expressions provide host-side scripting through Python.NET. The evaluator creates a Python scope for the expression and exposes workflow context, input, output, and outcome access through that scope.
Python host-code execution is disabled by default. Python.NET is not a sandbox, so the host must enable it only for trusted workflow authors and must provide a usable Python runtime. The Python descriptor is browsable only when host-code execution is enabled.
The Run Python activity evaluates a full Python script, stores a non-null result as its activity result, and completes with the outcome selected by the script, or Done when no outcome is selected.
References: src/…/PythonNetPythonEvaluator.cs• L17-61 src/…/PythonExpressionSyntaxProvider.cs• L11-25 src/…/PythonFeature.cs• L22-61 src/…/RunPython.cs• L30-70 src/…/PythonOptions.cs• L11-32
Service registration and activity use
Language feature registration
The base expressions feature registers the shared evaluator. Each language feature depends on it and registers its language evaluator and descriptor provider. The application selects the languages it supports by enabling the matching module features, such as UseCSharp, UseJavaScript, UseLiquid, or UsePython.
This arrangement gives the application one expression contract while allowing each language to bring its own engine, options, editor metadata, activity types, and extension points. A custom language can follow the same pattern by registering an IExpressionDescriptorProvider and an IExpressionHandler through its descriptor.
References: src/…/ExpressionsFeature.cs• L12-25 src/…/ModuleExtensions.cs• L22-35 src/…/ModuleExtensions.cs• L11-27 src/…/ModuleExtensions.cs• L11-28 src/…/ModuleExtensions.cs• L7-16 src/…/ModuleExtensions.cs• L10-19
Workflow activity integration
Activities normally declare typed inputs and let the workflow input pipeline evaluate them. The input points to an expression, while the activity receives the result in its own type. This makes language choice a property of the workflow value rather than a dependency in each activity's business logic.
Script activities are the explicit exception in purpose, not in contract. Run C#, Run JavaScript, and Run Python execute a script as workflow work and expose its result and outcomes. Liquid remains focused on producing rendered values for other activity inputs.
This diagram shows the relationship between ordinary expression-backed inputs and explicit script activities.
flowchart TD
A[Workflow definition] --> B{Expression-backed input or script activity}
B -->|Input value| C[Shared expression evaluator]
B -->|Run script| D[Language evaluator service]
C --> E[Typed activity input]
D --> F[Activity result and outcomes]
E --> G[Activity execution]
F --> G
References: src/…/ExpressionEvaluatorExtensions.cs• L13-29 src/…/RunCSharp.cs• L49-73 src/…/RunJavaScript.cs• L48-77 src/…/RunPython.cs• L47-70
Change checklist
When these files or sections are changed, remember to consider these:
- When an expression type name changes, update its descriptor, serialized workflow data, and any activity input that names it as a default syntax.
- When a language feature changes its registration, check that the shared evaluator can still find its descriptor and that the corresponding activity remains available.
- When context access changes, check every language boundary because JavaScript, Liquid, and Python expose workflow data through different names and adapters.
- When C# variable access changes, check generated property names, typed and dynamic variable access, and scripts that use the
VariableorVariablesproxy. - When JavaScript interop defaults change, check array mutation isolation, enum comparisons, async script results, and any workflow data crossing the CLR boundary.
- When host access or execution limits change, review both the feature options and the authorization policy for workflow definitions that use C# or Python.
- When a script activity changes its outcome contract, keep the script helper, possible-outcome input, and activity completion behavior aligned.
- When JavaScript type-definition access changes, keep the endpoint's required permission and the permission descriptor aligned so the editor can get workflow-specific IntelliSense.
- When a Liquid template or custom filter needs host configuration access, rendering lacks the requested configuration value or exposes data too broadly if enabled without review.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A workflow uses a language whose feature is not enabled | The shared evaluator cannot find a descriptor for the expression type | Enable the matching language feature before loading or running the workflow |
| C# or Python host-code execution is disabled | Evaluation fails instead of running workflow-authored code | Enable the option only for trusted authors and provide the required host runtime |
| A workflow uses JavaScript CLR or configuration access without the matching opt-in | The script cannot reach those host capabilities | Configure JintOptions deliberately and keep both options off for untrusted workflows |
| A JavaScript script expects CLR array mutation to update workflow data | The default copy boundary leaves the original workflow data unchanged | Use explicit live-view configuration only when the workflow needs shared mutation |
| An editor caller lacks JavaScript scripting view permission | The type-definition request is denied and JavaScript IntelliSense lacks workflow-specific types | Grant the permission through the host authorization policy to the intended workflow editors |
| An expression reads a missing input, variable, output, or context value | The result can be null or evaluation can fail when a required context is absent | Evaluate in an activity context with the needed workflow state and use the language's supported access form |
| A script selects an outcome that is not declared as possible | The activity can complete with a path that the workflow design does not expect | Keep the script outcome calls and PossibleOutcomes input consistent |
| A Liquid template or custom filter needs host configuration access | Rendering lacks the requested configuration value or exposes data too broadly if enabled without review | Register only the required access and do not enable it for untrusted workflow content |
Key files
| File | Why to read it |
|---|---|
| src/…/Expression.cs | Defines the serialized expression value and its type selector. |
| src/…/ExpressionExecutionContext.cs | Shows the workflow state and service boundary available to evaluators. |
| src/…/ExpressionEvaluator.cs | Shows common dispatch from an expression type to its handler. |
| src/…/ExpressionDescriptorRegistry.cs | Shows how expression descriptors become discoverable. |
| src/…/DefaultExpressionDescriptorProvider.cs | Shows the core value expressions provided by the workflow system. |
| src/…/CSharpEvaluator.cs | Shows the C# language boundary and its trust requirement. |
| src/…/GenerateWorkflowVariableAccessors.cs | Shows how C# scripts receive workflow-variable access through the Variable proxy. |
| src/…/JintJavaScriptEvaluator.cs | Shows JavaScript preparation, context setup, interop, host access, and execution limits. |
| src/…/Endpoint.cs | Shows the protected authoring service that returns JavaScript type definitions. |
| src/…/JavaScriptPermissions.cs | Defines the permission used to protect JavaScript editor type definitions. |
| src/…/LiquidTemplateManager.cs | Shows Liquid rendering and filter integration. |
| src/…/PythonNetPythonEvaluator.cs | Shows Python scope setup and its trust requirement. |
| src/…/RunJavaScript.cs | Illustrates how a language-backed activity returns results and outcomes. |
| src/…/CSharpFeature.cs | Shows how one language feature registers its evaluator, descriptor, and activity. |
| src/…/JavaScriptFeature.cs | Shows the broader JavaScript feature boundary and authoring support. |