When you run $zf(-100) from IRIS session terminal the external process is run in the OS context (secutity/permissions) of the OS user loggen in.

When $zf(-100) is run by a storedproc or studio is run in the OS context (secutity/permissions) of the OS user used by the IRIS instance.

You have permission and/or environment issue.

Why run python using $zf(-100)? You can use embedded python to avoid this issues, it is simpler and have better performance.

Despite the lack of details in the question, using a lot of imagination and fantasy, my guess is that you are using ^%SYS.MONLBL or ^PERFMON or %Monitor.System package classes.

If my guess is correct, then I'd suggest to check the chapter "Estimate Memory Requirements" in the "Examining Routine Performance Using ^%SYS.MONLBL" documentation page.