You don't, you find a US company with a local entity that hires you on a local contract in that country. That way you're compliant with taxes, and the company is compliant with employment law in your country.
The alternative to that is starting a sole-trader company in the country you're in, and contracting directly with the US company through it (or a remote-employees-as-a-service company that basically does this on the company's behalf for a fat fee).
sorry, my question is not that much of a legal side, there's plenty of info around - it's rather about identifying jobs which are open to this. Most HRs and hiring managers just ignore the applications which openly state - "I'm not on US soil".
The alternative to that is starting a sole-trader company in the country you're in, and contracting directly with the US company through it (or a remote-employees-as-a-service company that basically does this on the company's behalf for a fat fee).