This has been traditionally done using a freeware app called Soundflower - originally by Cycling 74, taken over by Rogue Amoeba but not developed or supported further. To record 'in-computer' sound, you need software that can re-route audio within the Mac itself - to make it think an output is actually an input.
To add external audio sources, you need to make sure the correct input is assigned before you start the recording