To be able to work in Costa Rica, it is necessary to apply for a working visa. Tourist visas do not permit legal work, but of course, volunteering is an option.
The thriving tourist trade obviously provides a great deal of work in Costa Rica for most months of the year. As a traveller, you may be in a position to find work in the most touristy areas. Seasonal bar work is a possibility.
Alternatively, if you plan to stay for a longer period and manage to get a working visa, a solid work option is teaching English. Even better if you arrive in possession of a TEFL qualification as you will be in a stronger position to negotiate decent working conditions. English teachers are in such high demand, though, that even without the TEFL qualification, it should not be a problem to find work. Positions are readily available in private language institutions, public schools and also within companies.
Voluntary work is a great thing to do if you really want to spend some time in the country and also want to access areas and situations that are not common to the regular tourist route. Many volunteer projects require you to raise a large sum of money in sponsorship. For this reason it is worth carrying out some detailed research well in advance if you are considering voluntary work as a serious option.