You haven't specified one specific country, but in general, the way to avoid problems is to carefully research the relevant immigration and labor laws in whichever country you want to go, then you acknowledge that many such offers may be illegal.
Many such arrangements are flatly illegal, and depend on lying about your intentions to immigration and simply not getting caught. While it's often possible to do legitimate volunteering on a tourist visa (e.g. in the USA), you run into problems quickly when the work is for compensation. Most countries with reasonable labor laws will not consider hours a day of farmwork on a commercial farm to be "volunteering," even if there's a vague promise to teach you about organic farming. Some countries may have a "working holiday" scheme or "cultural exchange" visa that allows for this type of work, but a reputable such opportunity will comply with minimum wage and other labor laws. That's not to say that many people don't skirt the law, get away with it, and have a great time and memories to last a lifetime, but you should at least know what you're getting into.
As an example, here's what WWOOF-USA has to say about visas:
Most WWOOFers enter the USA using a tourist visa; however, it is your responsibility to determine the correct visa for your visit. Please keep in mind that WWOOF is NOT paid work or volunteering. WWOOFing is an educational experience, and WWOOF members are guests of their hosts. The United States has extremely strict labor and immigration laws that prohibit foreign nationals from “working” or “volunteering” in the country without a work visa. Most international WWOOFers communicate their intentions to visit the USA to immigration officials and enter without any problems. However, if you say that you are coming to “volunteer or work on a farm” and you don’t have a work visa, immigration probably WILL NOT LET YOU ENTER THE USA. Additionally, please note that when entering the USA, you cannot enter as a “WWOOFer,” as the meaning of this may be misunderstood by immigration officials. If you say you are “WWOOFing” when you enter the USA (especially from the Canadian border), you will most likely be turned away and not allowed to enter the country. Please take this into consideration and plan your visit to the USA accordingly. If you are traveling from another country, please be aware of this important distinction: as a WWOOFer, you are a TOURIST, NOT a WORKER or VOLUNTEER. Please understand the laws and clearly communicate your intentions when you enter the country. WWOOF-USA is not responsible for any problems you may experience with immigration.
This should raise a large number of red flags. In contrast, here's what the US Embassy in Germany says:
Planning to work for room and board on a farm or as an Au Pair/Nanny?
Do Woofing? An internship? Even if you stay less than 90 days, these
activities are considered work and require the appropriate visa....
Informal arrangements to work in exchange for lodging or meals are
also considered unauthorized employment and are not permitted for
In short, do not rely on an organization like WWOOF to provide legal advice.
There is also the danger that, if you are working illegally, you are working for someone who has demonstrated that they are not inclined to follow labor laws. While many of the employers in these situations are surely fine caring people who can support your travels and teach you about the local culture, someone who is recruiting illegal workers may well not have the highest of scruples about accurately representing the conditions of employment or lodging. You could also run into significant problems if you get hurt, depending on local laws, as your travel insurance may exclude coverage for workplace injuries, and your host's insurance, if there is any, may exclude coverage for people working illegally.