Generally, yes, it is illegal to work in the US while present as a visitor. There are some exceptions for "business visitors" who must travel to the US to meet with clients or to supervise work being performed by US workers, but even then such a person should be in B-1 or WB status as a business visitor rather than B-2 or WT status as a tourist.
Working for a US employer is definitely prohibited, since, as noted by USCIS, income from a US source is disqualifying for a B-1 visa:
Requirement 3 - You cannot draw any salary from a United States entity.
It is permissible to conduct business activities on behalf of a foreign employer, but no salary may come from a U.S. source. In some cases, however, you may receive reimbursement from a U.S. source for reasonable incidental expenses incurred while in the United States.
As to working for foreign employers, you can have a look at Travel Stack Exchange, where the question I want to travel to the USA while working remotely for my non-US employer has several anecdotal answers describing visa denials and entry refusals for people who disclosed that they were planning to work remotely for their foreign employers. However, I found no unambiguous prohibition in Title 8 of the US Code nor in Title 8 of the Code of Federal Regulations. It is, however, very unlikely that it would be worthwhile to pursue a court challenge to the current policy.
As an aside, Canada has a different policy on this, as outlined in this Travel.SE answer (note that the category of "temporary resident" includes tourists):
Here's what the Immigration, Refugees and Citizenship Canada says about What kind of activities are not considered to be “work”?:
long distance (by telephone or internet) work done by a temporary resident whose employer is outside Canada and who is remunerated from outside Canada;