Back to glossary

Anti-Malware Scan Interface (AMSI)

AMSI is a Windows API that lets script hosts such as PowerShell send code to the installed antimalware engine for scanning right before it runs.

Also known as Antimalware Scan Interface, Windows AMSI

The Anti-Malware Scan Interface (AMSI) is a Windows API that lets an application hand content to the installed antimalware engine for a verdict right before it runs. PowerShell, Windows Script Host, and Office macros call AMSI after scripts are decoded, so obfuscation does not hide the code. AMSI only sees what an integrated host chooses to send.

That last limit is the one that matters for supply chain attacks. A malicious npm, PyPI, or Cargo package runs its first stage in Node.js, Python, or a Rust build script, and none of those runtimes is on Microsoft's list of AMSI-integrated components. AMSI is a useful layer on Windows endpoints, and it starts scanning only after the attacker's code is already running.

What is AMSI?

#

AMSI is an interface standard between two parties: hosts that run content and providers that judge it. Microsoft's AMSI documentation describes it as "a versatile interface standard" that lets applications integrate with "any antimalware product that's present on a machine." It arrived with Windows 10.

A host is any program that executes code it did not compile in advance: a script engine, a macro runtime, an installer. The host calls the AMSI API with a buffer of content. AMSI forwards the buffer to every registered provider, a COM component supplied by the antimalware product, and returns a verdict. Microsoft Defender Antivirus is the provider on most machines, and third-party products can register their own.

The Windows components Microsoft lists as AMSI hosts are User Account Control for elevation of EXE, COM, MSI, or ActiveX installs; PowerShell, covering scripts, interactive use, and dynamic code evaluation; Windows Script Host, which is wscript.exe and cscript.exe; JavaScript and VBScript; and Office VBA macros. Defender's documentation adds .NET Framework 4.8 assemblies and WMI, and notes that Exchange and SharePoint integrate too.

How AMSI scans code at runtime

#

AMSI scans the content a host is about to execute, not the file on disk. That is its whole point. Antivirus that reads files sees a script after its author has base64-encoded, split, and encrypted it. The script engine sees it after all of that has been undone, because it can only run plain code. Microsoft's guide to how AMSI helps makes the argument directly: script may go through several passes of de-obfuscation, but the engine ultimately needs "plain, un-obfuscated code," and that is where the host calls AMSI.

A host uses a small set of functions from amsi.dll. It calls AmsiInitialize once, opens a session with AmsiOpenSession so related fragments can be correlated, submits content with AmsiScanBuffer or AmsiScanString, and closes the session when done. Each scan returns an AMSI_RESULT, which the API reference defines like this:

C
typedef enum AMSI_RESULT {
  AMSI_RESULT_CLEAN,
  AMSI_RESULT_NOT_DETECTED,
  AMSI_RESULT_BLOCKED_BY_ADMIN_START,
  AMSI_RESULT_BLOCKED_BY_ADMIN_END,
  AMSI_RESULT_DETECTED
};

The reference lists the names without numbers. The header assigns explicit values, and the remarks define ranges rather than five fixed answers:

ResultMeaningHost should
AMSI_RESULT_CLEAN (0)Known good; unlikely to change with new definitionsRun it
AMSI_RESULT_NOT_DETECTED (1)Nothing found yet; may change with new definitionsRun it
1 to 32767Provider-specific risk estimate, higher is riskierDecide by policy
BLOCKED_BY_ADMIN rangeBlocked by administrator policy on this machineBlock it
32768 and aboveMalwareBlock it; check with AmsiResultIsMalware

Microsoft tells hosts to call AmsiResultIsMalware rather than compare constants, because "any return result equal to or larger than 32768 is considered malware."

AMSI fails open, and runs in the attacker's process

#

AMSI's two design properties explain both its value and its limits. First, PowerShell treats AMSI errors as a clean result. In PowerShell's own source, the scan wrapper returns AMSI_RESULT_NOT_DETECTED if AMSI failed to initialize, if AmsiScanBuffer returns an error, or if amsi.dll is missing, and PowerShell builds for Linux and macOS skip AMSI entirely. That choice keeps scripts running when the security stack misbehaves. It also means that breaking AMSI is the same as passing it.

Second, the scan happens inside the host process. The script being scanned and the code that asks for the scan share an address space and a user account. That is what makes AMSI precise, since it sees exactly what the engine is about to run, and it is also why AMSI is a layer of defense rather than a boundary.

What is an AMSI bypass?

#

An AMSI bypass is any technique that keeps malicious content from reaching the provider or forces a non-malicious verdict, so a script runs without being scanned. Because AMSI lives in the same process as the code it inspects, most bypasses tamper with that process's own AMSI state, or simply run the payload in a host that never calls AMSI.

We do not document bypass techniques here. For defenders, the useful facts are about detection. A bypass attempt is itself script content, so PowerShell submits it to AMSI before running it, and a provider can match known bypass patterns like any other malicious script. A bypass that works still leaves traces in PowerShell script block logging and in process and network telemetry. Treat a detected bypass attempt as a confirmed intrusion, not a blocked one, because the code that tried it is already running.

Does AMSI catch malicious packages?

#

AMSI catches a malicious package only when the attack reaches an AMSI host, which is usually its second or third stage. Package managers run install-time code in the language runtime: Node.js for npm lifecycle scripts, Python for setup.py builds and .pth startup hooks, and Rust for build.rs. Microsoft's Defender documentation says plainly that "AMSI doesn't currently support Python or Perl," and Node.js and Cargo are not on the integrated list either.

The axios compromise in March 2026 shows where the line falls. The malicious dependency's postinstall hook ran setup.js under Node.js and branched by operating system. On Windows, it copied PowerShell to %PROGRAMDATA%\wt.exe to pass as Windows Terminal, launched a hidden VBScript with cscript, downloaded a .ps1 script, and ran it with a hidden window and the execution policy bypassed.

The figure marks each Windows stage of that chain. Stage 1, npm install running node setup.js through the postinstall script, executes in Node.js, which is not an AMSI host. Stage 2, copying PowerShell to %PROGRAMDATA%\wt.exe, is a file copy, not script execution, so AMSI has nothing to scan. Stage 3, the hidden VBScript run by cscript //nologo, executes in Windows Script Host, which calls AMSI before running the script. Stage 4, the downloaded .ps1 in the copied PowerShell, is scanned by the PowerShell engine regardless of what the executable is named, and that scan fails open if AMSI errors.

Renaming PowerShell defeats detections keyed on process names. It does not remove AMSI, because the calls come from the PowerShell engine inside the binary, not from its filename. Stages 3 and 4 were visible to AMSI. Stage 1 was not, and by the time it ended, attacker-controlled code had already run with the developer's account, environment variables, and tokens.

That is the general shape. AMSI is a strong control for the malware it was built for: scripts, macros, and in-memory .NET loaded by a Windows host. Against a malicious package, it is a second-stage tripwire. The first stage runs in a runtime AMSI does not watch, on Linux CI runners where AMSI does not exist, and often never needs PowerShell at all.

Using AMSI well

#

Keep AMSI and its provider enabled, and keep definitions current, because the interface is only as good as the provider behind it. Turn on PowerShell script block logging so that deobfuscated content is recorded even when the provider says it is clean, and alert on AMSI detections from developer machines and build agents, where a script detection after a package install is a strong signal.

Do not count AMSI as coverage for dependency risk. A package firewall or install-time analysis that inspects what a package does before its lifecycle scripts run covers the stage AMSI cannot see, on every operating system. Our code obfuscation and behavior-based security pages cover how that analysis handles the same encoded payloads AMSI was designed to unwrap.

AMSI got one idea exactly right: scan code at the moment it becomes plain enough to run. Package managers have that moment too, before an install script executes, and it is still the place most supply chain attacks go unscanned.