Server-side Lua scripting in Orthanc

Lua scripts let Orthanc follow your workflow without a compiled plugin. This page covers what they do, how to install and test them, and when a team should move to Python.

On this page

When Lua scripting in Orthanc fits your workflow

Choose Lua scripting when your team needs Orthanc to react to incoming studies or run routine REST actions, but building and maintaining a compiled plugin would be more than the job justifies. A Lua script loads into the running server, so you can attach behavior to server events such as instances being received, stored or changed, and you can filter incoming instances before they are accepted. Typical uses include rejecting C-STORE transfers that fail a site rule, tagging studies as they arrive, or forwarding a copy of a study to another destination once it is stored. The REST API alone cannot do this, because it only responds when a client calls it. A script runs inside the server and reacts without an external poller.

Lua is one of several extension routes for Orthanc. Teams that need richer libraries, new REST routes with more logic, or heavier processing usually look at the Python or Java routes covered in the sibling topics. The practical test is scope: if the behavior is a few event handlers and simple decisions on tags, Lua is usually proportionate. If the team expects to maintain substantial logic, shared libraries or complex data handling, confirm early that a scripting route will still be maintainable in two years. Before committing, check which events and filters your Orthanc version exposes in the official Orthanc Book, because callback names and behavior can change between releases.

Confirm three things before you write the first script. First, who owns the script after the project ends, since a Lua file on the server is easy to edit and easy to forget. Second, whether the script needs to call the REST API, which brings in authentication and the question of which account it runs under. Third, whether any part of the workflow touches the /tools/execute-script or export routes, which the Orthanc security FAQ warns should stay disabled. If a planned script depends on those routes, redesign the workflow rather than enabling them.

Lua scripting options and when each fits

This table compares the four ways to extend Orthanc's behavior: Lua scripts, the Python plugin, the Java plugin and external clients calling the REST API. Read each row as a question about your team and workflow, and use the main trade-off column to decide which route fits before any build starts.

RouteBest suited toWhat the team needsMain trade-off
Lua scriptsSmall workflow rules such as filtering incoming instances, tagging studies and reacting to events, running inside the Orthanc processSomeone comfortable with Lua, access to the Orthanc configuration and a test server to confirm callback names and behaviorLightweight and close to the server, but concurrency and error handling need care and callback names must be checked in the Orthanc Book
Python pluginLarger logic such as new REST routes, pydicom processing, scheduled tasks and custom storage handlingPython developers, a deployment process for plugin packaging and the AGPL obligations reviewed for your scriptsRicher libraries and more capacity than Lua, at the cost of a heavier build and release process to maintain
Java pluginTeams with an established Java stack that need compiled extensions, event handlers and queuesJava developers familiar with the Orthanc SDK, packaging and a build pipelineStrong fit for Java shops, but a higher setup effort than scripts and a different skill set from the rest of the workflow
External REST API clientRoutine archive work such as jobs, exports and transfers run from a separate service or schedulerA service account, authentication handling for the REST API and monitoring of asynchronous jobsKeeps logic outside the server and easy to replace, but every call adds network and authorization steps
Lua callback names and Lua versionConfirming which events and functions your Orthanc version exposes before you write codeAccess to the official Orthanc Book for the version you runVersions and callback names change between releases, so verify them in the Orthanc Book before relying on them

How to install and test a Lua script in Orthanc

This sequence takes a team from a confirmed Orthanc version to a Lua script that loads on startup and has been checked against a non-clinical sample study. Each step ends with a check, so a failure is caught where it happens rather than during a later clinical test.

  1. Confirm the Orthanc version and install route

    The platform team records the exact Orthanc core version it will run, along with the install route it will use: Docker image, Windows installer or a Linux package for Debian, Ubuntu, openSUSE or FreeBSD. The current release line is listed on the Orthanc download page, and the release history is in the Orthanc NEWS file, so compare the version you plan to run against the Lua features described in the Orthanc Book for that release. Done when the version string and install method are written into the change record and the team has confirmed the Lua examples they plan to use match that version.

  2. Install Orthanc on a non-clinical host

    The platform engineer installs Orthanc on a test host or test container that has no connection to production modalities, PACS or patient data. For Docker, the image is started with its configuration directory mounted so the script can be placed on the host. Confirm that the server answers on its REST interface from localhost, since Orthanc only accepts HTTP connections from localhost by default. Done when the system information endpoint returns the expected version and the server runs without errors in its log.

  3. Place the Lua script in the script directory

    The engineer copies the Lua file into a directory the Orthanc process can read, keeping it under version control alongside the configuration. The file should be named clearly, for example after the workflow it serves, and should not contain credentials. Check file ownership and permissions so the service account running Orthanc can read the file. Done when the file exists at the chosen path on the test host and the permissions match what the Orthanc service account needs.

  4. Reference the script in the configuration

    The engineer adds the script path to the Orthanc configuration file using the Lua script key documented in the Orthanc Book for the installed version. Exact key names and their accepted forms change between releases, so the engineer confirms them against that version's configuration reference before editing the file, rather than copying a key from an older example. Done when the configuration file parses without errors and the path points to the file placed in the previous step.

  5. Restart and confirm the script loads

    The engineer restarts Orthanc so the configuration takes effect, then reads the startup log. A successful load shows the script path and no Lua syntax or runtime error messages. A failed load usually appears as an error naming the file and line, so fix the reported problem and restart again. Done when the log shows the script loaded without errors and the server still answers its REST interface.

  6. Test with a non-clinical sample study

    The tester sends a sample study that contains no real patient data, such as a publicly available teaching dataset or a synthetic study generated for testing, using the Orthanc web interface or a DICOM send from a test modality. The tester checks that the script's callback fired by comparing the log output and the resulting instance or study state with the expected behavior written in the test plan. Done when the expected result is observed for the sample study and the same check is recorded for each callback the script uses.

  7. Record results and gate promotion

    The team writes down the Orthanc version, the script version, the configuration change, the test study used and the observed results. Before the script is considered for a shared or clinical environment, the security and clinical owners review it, and the security settings in the Orthanc Book are checked, including that the script-execution and export routes remain disabled. Done when the record is complete and the owners have signed off on moving to the next environment.

How event callbacks and REST calls behave in Lua

Lua callbacks run inside the Orthanc server process as events happen, so a script's behavior is part of how the server handles every incoming instance, not a separate job running beside it. When a new DICOM instance arrives, Orthanc raises an event and the script can inspect the data, accept it, or reject it. Because the callback sits on the path of storage, the team should treat each callback as production code that can slow or block ingestion. Before building anything, confirm the full list of event hooks, their arguments and what each one can return against the Orthanc Book scripting documentation for the exact Orthanc version in use, since the callback surface is the contract the script depends on. The supplied sources do not list those callbacks here, so do not rely on names from older examples without checking them.

Treat ordering and speed as design constraints. Events are handled as the server reaches them, and a slow callback delays the work queued behind it, so a script that makes a long network call or waits on a busy downstream system can back up a whole ingestion flow. Keep callback logic short, move slow operations to asynchronous REST jobs where possible, and measure how long each callback takes under a realistic load test in a non-production environment. Ask whether the same event can fire more than once for the same instance, for example after a retry from a sending modality or after a manual resend, and whether the server will re-raise events during restarts or recovery.

Write every script so that repeating it produces the same result. A callback may run twice for one instance, and a REST call made from the script may time out and be retried, so the script should check whether the work is already done before acting. For example, before forwarding or relabeling an instance, look it up by its identifiers and skip it if the outcome already exists. Log each decision with the instance identifier so the team can reconstruct what happened. When a script calls the local REST API, use a dedicated service account with the minimum rights it needs, and confirm in the Orthanc security documentation how authentication applies to local calls before enabling remote access.

Concurrency pitfalls that break Lua workflows

Lua callbacks in Orthanc run alongside REST traffic, bulk ingest and other Orthanc instances, so a script that works on one study can fail under load. The cards below cover the risks that appear most often when a workflow moves from a single test server to a shared, production archive. Each one names the symptom to watch for and the control to put in place before go-live.

Blocking callbacks during bulk ingest

Lua event callbacks such as the instance-received hook run in the path of incoming DICOM traffic. A callback that makes slow REST calls, writes large files or waits on an external service can back up C-STORE transfers and delay every sender. Symptom: modalities report timeouts while the script is still running. Mitigation: keep callbacks short, push slow work into queued jobs, and load test with a realistic bulk transfer before release.

Duplicate processing across instances

Since Orthanc 1.9.2 with PostgreSQL or MySQL/MariaDB plugin 4.0, several Orthanc instances can read and write the same database, which is how horizontally scaled and highly available setups are built. Each instance runs its own copy of the Lua script, so a forwarding or tagging action can fire once per instance for the same event. Symptom: duplicate forwards, double notifications or repeated tags. Mitigation: make each action idempotent, check the state in the database before acting, and decide which node owns scheduled work.

Race conditions on shared state

Lua globals live inside a single Orthanc process, so a counter or cache kept in a global is not shared with other instances and can be read and written in an interleaved order within one instance. Two events for the same study can arrive close together and each see an incomplete view. Symptom: counts that drift, studies marked complete too early or overwritten status values. Mitigation: store workflow state in Orthanc metadata or an external database with atomic updates, and test with events arriving out of order.

Unbounded REST job loops

A Lua loop that polls job status or calls REST endpoints for every instance in a large study can create far more requests than the server is sized for. Loops without a timeout or maximum attempt count can run indefinitely when a job stalls. Symptom: rising CPU, a growing job queue and scripts that never return. Mitigation: cap iterations, add a deadline to every wait, and use asynchronous jobs with a monitored queue rather than tight polling.

Errors swallowed silently

A failed REST call or a nil value inside a Lua callback may not surface to the user who sent the study, and a script that catches errors without logging them leaves no trace. Missing data then appears later as an unexplained gap in routing or anonymization. Symptom: studies that never reach the destination with no alert. Mitigation: log every failure with the instance identifier, route failures to a visible queue or error tag, and review logs as part of acceptance testing.

Script changes applied during live traffic

Orthanc loads Lua scripts at startup, so editing a file on a busy server changes behavior for studies arriving afterward, possibly mid-transfer. A partially edited script or a change deployed to only some instances can leave the cluster running different rules. Symptom: studies handled differently depending on arrival time or instance. Mitigation: version scripts in source control, deploy to all nodes in a planned window, restart in a controlled order and confirm the loaded version after each change.

How an incoming instance moves through a Lua filter

The flow starts when a modality or peer sends a C-STORE request across the network boundary into the Orthanc process. Inside Orthanc, the Lua callback for incoming instances inspects the DICOM tags and returns a decision: accept, modify or reject. Only accepted instances reach the storage area and index, while rejected ones are refused and never stored. A script can also call the local REST API for follow-up work, and that call stays on the server. Check that every branch of the callback returns a decision, and that the callback does not depend on state it cannot guarantee.

Trust boundary between the remote sender and the Orthanc process during C-STORE filtering.

Security rules for scripts on a patient-data server

A Lua script runs inside the Orthanc process with access to the archive, so a script can be as risky as the routes around it. The cards below cover the routes to keep closed, the network and authentication settings, the credentials scripts use, who may change script files, and the audit trail for script decisions.

Keep execute-script disabled

The Orthanc security FAQ warns that the /tools/execute-script route can let a malicious user run any system command on the host. Scripts written for a workflow do not need this route, so keep it disabled in production. Check the live configuration after every upgrade or container rebuild, and confirm that no reverse proxy rule exposes it to users or other services.

Security FAQ

Keep the export route disabled

The same security FAQ warns that the export route can overwrite files on the server. A Lua filter or callback that needs to write files should write to a directory the Orthanc service account owns, not rely on a generic export endpoint. Review which paths scripts can touch, and confirm that the export route is not reachable from the network segment where clinical users sit.

Keep remote access off or authenticated

By default Orthanc accepts HTTP connections only from localhost. If RemoteAccessAllowed is enabled, the docs say AuthenticationEnabled should be true with users defined in RegisteredUsers. Scripts that call the REST API from another host inherit this boundary, so they need credentials that match a defined user and role.

Security FAQ

Use HTTPS and a reverse proxy

For any exposure beyond the local host, the docs recommend HTTPS and a reverse proxy. Terminate TLS at the proxy, limit which paths it forwards, and block the script-execution and export routes there as a second layer. Ask your network team to confirm that the proxy, not Orthanc, holds the certificates and that access logs are retained.

Manage credentials used by scripts

Scripts that call the REST API need a user account, and that account should hold only the permissions the workflow needs. Avoid hardcoding passwords in Lua files that many people can read. Store them in a restricted configuration file or a secrets manager, rotate them on staff changes, and confirm that the account cannot administer users or change configuration.

Control who changes script files

A changed Lua file can alter how every incoming instance is stored, filtered or forwarded, so treat script files as production code. Restrict write access on the server to a small group, keep scripts in version control with reviewed changes, and record who deployed which version. Confirm that a script change requires a service restart or reload in your setup before relying on it.

Log script decisions for audit

When a script rejects, modifies or forwards an instance, the decision should leave a trace that compliance staff can review later. Write a log line with the study identifiers, the rule that fired and the outcome, while keeping patient names and other identifiers out of general-purpose logs. Check where Orthanc writes its logs, how long they are kept, and who can read them.

When a Lua script should move to Python

A Lua script should move to Python when its logic outgrows what Lua callbacks handle well. The usual triggers are simple: the script needs a richer library such as pydicom to parse or modify pixel and tag data, it must run scheduled tasks or custom storage handling, or the team now expects it to be tested and released like application code. Filtering a few tags on C-STORE can stay in Lua for a long time. A script that parses private tags across many series, calls external services with retries, or keeps state between runs is a signal to reassess. Before deciding, list each callback the script uses and each external dependency it touches, then check which of them the Lua environment supports in your Orthanc version by reading the current Orthanc Book.

Moving is a rewrite, not a copy. Budget time for translating each callback, rebuilding the test cases that the Lua version passed, and running both scripts side by side on the same incoming traffic until their outputs match. Keep the Lua script in place during that period so a rollback is a configuration change. Confirm who owns the work, whether it is your staff or a partner, and ask for the parallel-run and cutover steps to be written into the scope. Changes to the Python plugin also need a planned Orthanc version check, because the core now ships releases such as 1.13.0 that change storage and parsing internals.

Licensing changes with the language. The Orthanc core is licensed GPLv3 or later, and the scalability and cloud plugins are licensed AGPLv3 or later, so confirm with your legal or compliance team which license applies to each script you distribute or run as a network service. Ask counsel to review how the AGPL network-use terms apply to any Python code that users reach over the network. The Orthanc Book licensing FAQ is the starting point for that review, and it should be reviewed again before any change to how the scripts are shared.

Questions buyers ask about Orthanc Lua scripting

How much effort does a first Orthanc Lua script take?

A first script that reacts to an event or filters incoming instances is usually small, but the effort depends on the workflow it has to match, not on the Lua code itself. The main drivers are how many events and REST calls the workflow touches, how many DICOM tag rules must be agreed with clinical and data owners, how many modalities or sites send data, and how well the current behavior is documented. Ask for a written list of events, tag rules and failure behaviors before any quote, because that list determines most of the work.

Can an internal team build Orthanc Lua scripts on its own?

Often yes, if the team has someone comfortable with Lua, the Orthanc REST API and DICOM basics, and time to test against real traffic patterns. The harder parts are concurrency behavior, error handling when Orthanc is under load, and keeping a change history that an auditor can follow. Teams that lack one of these skills usually bring in outside help for review or for the first release, then maintain the scripts internally. Your engineers should be able to explain every callback in the script before it reaches production.

What does the work need from our side?

Plan for three things before the build starts. First, representative test data, ideally de-identified, that covers the modalities, transfer syntaxes and malformed cases your workflow sees. Second, a staging Orthanc that matches production's version, database plugin and storage layout closely enough that results carry over. Third, a named owner who can approve tag rules, sign off on test results and decide what happens when a filter rejects an instance. Without the third item, testing tends to stall at the first disputed rule.

How long does testing take for a complex Lua workflow?

Testing time grows with the number of paths the script can take. A script that only logs or tags instances has few branches. A script that rejects, modifies or routes instances, calls the REST API and runs alongside other plugins has many more combinations of inputs, timing and failure. Ask for the test plan to list each path, the test data that exercises it, and the staging runs needed for load and retry behavior. Any duration in a quote should map to that list.

What does a fixed-scope engagement with DeployOpen cover?

DeployOpen works from a written scope that names the workflow, the Orthanc version and environment, the events and filters to implement, the REST calls to make, the test cases, the documentation and the handover. Most engagements are fixed-scope, so deliverables and timelines are agreed in writing before work starts. Changes to the scope after signing go through a written change request. Ongoing upgrades and testing are available separately as a retainer.

Do Lua scripts survive Orthanc upgrades?

Scripts depend on the events, functions and REST behavior of the Orthanc version they were tested against, so each upgrade needs a regression run, not just a restart. Check the release notes for the target version before upgrading, and retest anything that touches storage, DICOM parsing or transcoding, since those areas change between releases. The 1.13.0 release on 2026-08-15 rewrote storage-area access and DICOM parsing and transcoding, which is a clear example of why scripts need retesting after an upgrade. Keep scripts in version control and pin the Orthanc version they were proven on.

What changes if we later move from Lua to Python?

The workflow logic, tag rules and test cases carry over, but the code, packaging and deployment change. Python plugins run as a separate integration with their own dependencies, so you will need a plan for how they are installed, updated and reviewed. Licensing also changes: the Orthanc Book states that the core is GPLv3 or later, while certain plugins are AGPLv3 or later, so confirm with counsel what obligations apply to your scripts before you distribute them. Keeping the rules documented separately from the code makes a later move much cheaper.

How DeployOpen scopes and delivers Orthanc scripting

DeployOpen plans, implements and supports self-hosted open-source platforms inside your own infrastructure, and Lua scripts for Orthanc are treated as part of that platform. We scope the workflow hooks, test them against your modality traffic and REST clients, and hand over the scripts with the documentation your team needs to run them.

How we scope

  • Map each workflow event your team wants to hook, such as incoming instances, stored studies and REST calls.
  • Record which Orthanc configuration keys, script files and Docker or package layouts the scripts depend on.
  • Agree in writing the scripts, test cases, documentation and handover items, since most engagements are fixed-scope.

How we build

  • Write Lua callbacks for filtering and routing, keeping logic that needs heavier processing out of the event path.
  • Test callbacks against sample DICOM traffic from your modalities and check behavior under concurrent C-STORE load.
  • Confirm that the script-execution route and file export route stay disabled as the Orthanc security FAQ recommends.

How we hand over

  • Deliver scripts under version control with the installation steps for your Orthanc hosts and container images.
  • Document each callback, its configuration dependencies, its logging output and the known limits of its REST calls.
  • Walk your operations and integration staff through the test suite so they can rerun it after an Orthanc upgrade.

How we support

  • Offer ongoing support, upgrades and continuous testing for scripts as a retainer after handover.
  • Retest scripts when Orthanc releases change event behavior or the Lua interface your scripts rely on.
  • Review the scripts again if your workflow moves to Python, so both implementations are kept in step during the transition.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.