In worst case , fly to another country from Bkk , and buy the ticket when you get into your described problem. Like a plan B or C. Prepare for that, check which near country ( and therefore cheap ticket) doesnt need a visa.
education visa. Marriage. The same way you entered till now . Get a job + workpermit and visa. Elite visa. Retirenment visa. Just google a bit the requirements and you will have more detailed questions and better answers.
The ask:thailand community, consisting of multiple Q/A groups with over 100,000 members, powers this platform. It is not an official government resource. Our members actively contribute to this resource, and while we strive for accuracy, we cannot guarantee its complete reliability. Assistance to travelers is provided as a community service.