There is some debate on the issue, but the consensus is that you can't work while you're in the US independently of where the company you work for is located.
This article explains this:
But the grumble of many job-ready H4 visa holders is that they’re also banned from working remotely for companies back in their home nation. Freelancing, or even continuing to run a business abroad with no trading links to the U.S., would be a violation of the terms of the H4.
And there can be found similar explanation in a lot of places, like this one:
The reality is that the laws regulating H-4 status do not not necessarily contemplate a person working remotely but the existing laws explicitly state that a H-4 dependent cannot work unless he or she is the approved beneficiary of an authorized petition and been granted a change of status to a non-immigrant category.
So the answer is: you can't legally work - even if its remote work for a foreign company or freelancing.
There might be however some ways how you can still earn a little income.