exec format error in WSL - which of the two directions you are in
WSL runs two kinds of programs, and exec format error means one of them crossed a boundary
it cannot cross. The diagnosis is the same in both cases: find out what the file really is.
The kernel behaviour described here is verified on Linux; the WSL-specific interop behaviour is from Microsoft's issue tracker (linked below) rather than measured in this lab — treat the fix table as the practical part.
Direction 1: trying to run a Windows program from Linux
WSL lets Linux run .exe files through a binary-format handler (interop). When that handler
is missing — interop disabled in wsl.conf, or a distro that ships without it — the same
command fails:
$ ./tool.exe
-bash: ./tool.exe: cannot execute binary file: Exec format error
Microsoft tracks this class of failure in microsoft/WSL#8952 ("cannot run .exe files: exec format error: wsl.exe"), where the repro is: interop not disabled, yet the handler is still missing.
Check it:
$ cat /proc/sys/fs/binfmt_misc/WSLInterop # present?
enabled
interpreter /init
$ cat /etc/wsl.conf # interop switched off?
[interop]
enabled = false
If WSLInterop is absent, Linux has no idea what to do with a PE binary. Restart WSL from
Windows after fixing wsl.conf:
wsl --shutdown
Or: it is a Linux binary after all
A file named tool.exe can still be an ELF file (cross-compiled, or simply misnamed). Then
the error has nothing to do with interop:
$ file ./tool.exe
ELF 64-bit LSB executable, ARM aarch64 ← not a Windows program at all
That is direction 2.
Direction 2: a Linux binary built for another CPU
This is the more common case in practice, because WSL shares your Windows machine's CPU, and files travel: downloaded release artifacts, binaries copied from a server, Docker images built elsewhere.
$ file ./app
ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV)
$ uname -m
x86_64
$ ./app
bash: ./app: cannot execute binary file: Exec format error
aarch64 binary, x86_64 host. Nothing about WSL caused it; the kernel refused the machine
type exactly as it would on bare metal.
The reverse happens on Windows on ARM (Snapdragon laptops): WSL there is aarch64, and every
amd64 Linux binary fails the same way.
Direction 3: Docker Desktop, WSL2 backend
$ docker run --rm --platform linux/amd64 alpine uname -m
exec /bin/uname: exec format error
Docker inside WSL uses the same binfmt_misc mechanism. On x86-64 Windows, an arm64 image
cannot run; on Windows on ARM, an amd64 image needs Rosetta or qemu registered. Docker
Desktop handles some of this for you (Rosetta on Apple Silicon, emulation on Windows), but
the failure mode is identical when it is not available.
Measured on Linux with the same kernel path:
$ docker run --rm --platform linux/arm64 alpine:3.20 uname -m
exec /bin/uname: exec format error
$ docker run --privileged --rm tonistiigi/binfmt --install arm64
$ docker run --rm --platform linux/arm64 alpine:3.20 uname -m
aarch64
One triage sequence that covers all three
file ./thing # ELF (which machine?) or PE (Windows?) or script?
uname -m # what this WSL distro actually is
cat /proc/sys/fs/binfmt_misc/WSLInterop 2>/dev/null || echo "no interop handler"
| Result | Meaning | Fix |
|---|---|---|
PE32+ executable (console) x86-64 |
Windows program, no interop handler | Re-enable interop in /etc/wsl.conf, then wsl --shutdown |
ELF ... ARM aarch64 on x86_64 |
Wrong architecture | Install the x86-64 build |
ELF ... x86-64 on aarch64 |
Wrong architecture (Windows on ARM) | Install the arm64 build |
ELF ... Intel 80386 on x86_64 |
32-bit binary | Needs 32-bit libs (dpkg --add-architecture i386) |
ASCII text executable |
A script whose interpreter is missing | Check the shebang line — this reports bad interpreter, not cannot execute |
That last row matters: if the interpreter is missing, the message is different. Seeing
cannot execute binary file means the file is not a script bash can read.
The mistake to avoid
chmod +x and sudo are the two reflex fixes, and neither can work here: the file is
already executable, and privilege does not change an instruction set or a missing handler.
Check the file type first — one command, and it splits the problem in two.
For the binary case, ELF Inspector shows the machine type and whether the binary is static, without uploading anything: paste the file, read the header.
Kernel-level failure and the qemu before/after result were measured on Docker 29.1.3 / kernel 7.0 x86-64. WSL interop behaviour is cited from microsoft/WSL#8952 and the WSL documentation; it was not reproduced in this lab.