Foreign nationals living in the United States cannot work unless they have received explicit permission under the terms of their visa or other status, or have separately applied for and received a work permit.
A work permit is a photo identity card issued by U.S. Citizenship and Immigration Services (USCIS). It is also called an Employment Authorization Document or EAD. The EAD looks a lot like a driver's license. Its holders can show it to employers in order to prove their right to work. All U.S. employers must, when hiring a new employee, request proof of their immigration status or right to work -- employers who violate this rule can face sanctions.
All green card holders automatically have permission to work. They simply need to show their green card to employers.
Immigrants who go on to become U.S. citizens can, of course, work, and will be able to show their U.S. passport or naturalization certificate to employers.
Foreign nationals who have obtained work-based visas, which have been sponsored by U.S. employers, are also eligible to work in the United States. For example, such visas might include an H-1B (for specialty workers), an L-1 visa (for intracompany transferees), an E-3 visa (only for Australians), or an E treaty trader or treaty investor visa (for employees of companies registered as treaty traders or treaty investors in the United States).
There are numerous classes of other people who can (and must, if they wish to accept employment) apply for a special "work permit" from U.S. Citizenship and Immigration Services (USCIS). They must submit their application before they start working. The categories include things like K-1 fiance visa holders, asylees, people with a pending application for adjustment of status (a green card) spouses of various visa holders, people with Temporary Protected Status (TPS) or Deferred Enforced Departure (DED), F-1 students experiencing economic hardship or seeking optional practical training (OPT), and so on. The categories are too many to list here -- you can find a full list of them in the instructions that go with USCIS Form I-765 (the work permit application form). Notice, however, that there is no category for tourists (B-1 visa holders) or undocumented immigrants. USCIS will not grant these people permission to work in the United States, and indeed for them to do so (or for employers to hire them) is illegal.
In order to apply for an EAD, you'll need to fill out USCIS Form I-765, attach documentation showing that you're in a category of people allowed to apply for work permits, and attach photos and the appropriate fee. (Read the instructions carefully -- some categories of applicants are not required to pay a fee.) You'll need to submit the application to USCIS by mail. Expect to wait several weeks for a reply. See How to Apply for a U.S. Work Permit (EAD) for more on the process.
If you have any questions about whether you are eligibility for a work permit, or you want help with the application process, consult an immigration attorney.