Julia fails in mxc (Microsoft Execution Containers)

But it can be fixed!

I came across mxc a few days ago and thought it would be interesting to try to sandbox a Julia REPL. I’m using v1.12.6 and v13.0. Unfortunately, using/import fail due to issues with the win32 system calls in longpath and realpath within loading.jl. It also potentially impacts env_project_file due to directory walking outside of sandbox forced by base_project (I need to re-test in latest windows build).

This also hit node and git, but not cpython.

The latest windows build (9711) fixes the underlying issue in realpath (mount-manager/dos name resolution in GetFinalPathNameW) but not for GetLongPathNameW (maybe due to different mechanics, but not certain). Interestingly, cpython has a nonstrict fallback for realpath and i don’t see any use of GetLongPathNameW. Perhaps their approach can be copied? A fix for longpath is to use similar code we see in the fallback code for isfile_casesensitive. The use of readdir() there works fine due to using different and unaffected system calls.

What would be the likelihood of getting longpath in loading.jl patched?

The alternative is ugly but can be done. Manually patch longpath, ensure it hits everything required for import/using (in module.jl and loading.jl) and bake into own sysimage. Alternatively, you can grant readonly access to root directories, which rather defeats the purpose of sandboxing but can be used for testing at least.

I also saw an issue with Base.iswritable(path) but I think this is also fixed in the latest windows build (I’ll re-check).

The final roadblock is when child processes are spawned in mxc, which appears to require relocatable images. Checking the PE information of 7z.exe and zstd.exe files included under Base.PRIVATE_LIBEXECDIR shows that they are shipped as non-relocatable. lld.exe and dsymutil.exe are relocatable so aren’t an issue. But dll paths used by lld.exe etc. do need to have read access from the sandbox. Pkg.PlatformEngines.exe7z()/exezstd() can be overridden to point to new relocatable executables, or the existing files can be overwritten.

With these changes, I managed to get a REPL going, install packages etc. and eg cd outside of the sandbox was restricted.

I think that’s it.
Mike