Yes, you can install macOS on a USB drive and run it from there. This is called creating a bootable macOS USB drive. You need a large enough USB drive, the macOS installation application, and utilities to create a bootable drive. Just follow the steps for your macOS version and hardware. Please note that it may run slower than an internal drive.