You can not legally work in Thailand as a "freelancer"/ "digital nomad"/ etc. You CAN legally establish a business, and get a long term visa and work permit. However, it does require meeting certain revenue requirements, and potentially hiring certain amount of Thais. You also may not be able to own 51% of the business either.
I recommend reaching out to the Board of Investments
*************
Or the Joint Foreign Chamber of Commerce (they are responsible for encouraging foreigners to establishing businesses)
********************
And see if anyone can help