pkgx & Scripting

pkgx is a “Universal” Interpreter

$ pkgx ./
pkgx: running python ./

$ pkgx ./script.ts
pkgx: running: deno run ./script.ts

$ head -n1 ./script
$ pkgx ./script
pkgx: running: ruby ./script

We read the shebang and install the interpreter before executing the script. If there is no shebang we use the default interpreter for the file extension.


You can use pkgx as the shebang for your scripts:

#!/usr/bin/env -S pkgx python@3.9

import sys

$ chmod +x ./
$ ./

Using env to invoke pkgx is typical for tools that have no POSIX location.

The -S parameter is required to pass multiple arguments.

Including Additional pkgs

Scripts are the glue that allows open source to be composed into powerful new tools. With our +pkg syntax you make anything in open source available to your script.

#!/usr/bin/env -S pkgx +openssl deno run


Shell Scripting


eval "$(pkgx --shellcode)"
# ^^ integrates `pkgx` during this script execution

env +openai
# ^^ requires integration

openai --version

Robustness requires precisely specifying your environment:

#!/usr/bin/env -S pkgx bash>=4

source <(pkgx --shellcode)
# ^^ bash >=4 is required for this syntax, and eg macOS only comes with bash 3

Super Portable Scripts

If you like you can use our cURL-installer in your scripts. If pkgx is installed then the script just exits and uses that pkgx, if it’s not installed, it installs pkgx to a temporary directory first.


eval "$(curl -Ssf"

which pkgx   #=> /tmp/
echo $PATH  #=> /tmp/$PATH

pkgx +node@16 which node  #=> /tmp/

Last updated