My understanding of “foreign sourced” is that it usually applies to things like pensions, dividends, rental income. If you’re working, the source of the income is where you do the work - not saying you can’t fly under the radar and not pay tax, and each country has its own specific nuances and laws so Panama may allow it, but if you’re living and working remotely in a territorial tax country then that’s “locally sourced income” unless you can find laws or rulings to the contrary.
“The general rule for sourcing wages and personal services income is controlled by *where the service is performed*. The residence of the recipient of the service, the place of contracting, and the time and place of payment are irrelevant.” - https://www.irs.gov/pub/int_practice_units/ftc_c_10_02_05.pd... (my emphasis)