There are different laws in all countries that govern the ability of no-residents to legally work and Thailand requires anyone wishing to work there to obtain a Thai work permit. Anyone can get one if they meet the requirements, file the necessary paperwork and pay a nominal fee.
The first thing you have to consider when attempting to work in Thailand is whether or not the job you want to perform is permissible under Thai law. Foreigners are highly restricted as to the type of work they can do with the primary rule being that foreigners can only do work that Thais cannot do. So most jobs that foreigners have they have because proficiency in their native language is a requirement for their job. For example, an English teacher or a sales rep that needs to communicate with foreign customers. There are many others, of course, but whatever the job is, it must be something that requires a foreigner to do and not a Thai.
If the job is something that is eligible for a foreigner to perform then the company that the person wants to work for must prepare and file the necessary paperwork on their behalf. The first step in this process is for the company to provide the applicant with a letter stating their intention to hire him and provide him with a work permit. The applicant then must use this letter to travel outside of Thailand to a Thai embassy where they need to apply for a non-immigrant B visa. Non-immigrant O visas can also be used to get a work permit but B visas are much more common for this purpose.
After the applicant receives the non-immigrant visa then the rest of the paperwork can be prepared and the work permit can be applied for at the Thai Labor Department. The paperwork consists of various company documents primarily but also some personal documents from the applicant including a passport copy and a health certificate which can easily be obtained from any clinic or hospital. A blood test is required to check for, of all things, syphilis. Apparently it is considered more important than HIV for some reason as there is no test done for that.
After all of the paperwork is put together and presented to the Labor Department it takes anywhere from 7-10 days for the work permit to be granted. If there is a problem with the paperwork then the process will start all over again so it is best to make sure that you have the paperwork prepared by someone who is knowledgeable to avoid unnecessary delays.
Something else that is important to understand is that it is mandatory for anyone who is engaging in any type of work in Thailand to have a valid work permit. Working without a work permit can result in a fine for the company that hired the person and possible deportation for the person working illegally. You can't even volunteer for an NGO here without having a work permit. And working for a foreign company, say as a freelancer working online, is also illegal. So make sure if you do any work in Thailand that you have a work permit or you could be facing a lot of trouble.