What is needed to work legally in France as a freelancer for a foreigner?, I'm specially interested in knowing what is needed when the person is not from the European union, the US, or countries in the Schengen area.
If you are legally present in France, then you would need to register as an entrepreneur, pay necessary taxes, etc. Web Developers are probably considered as une profession liberale, and the necessary steps can be undertaken through the URSSAF site. (Registering as an autoentrepreneur would require holding long-term residence card.) Running such microentreprise is not very complicated, but there are a few pitfalls to avoid, and knowing French is certainly a necessity to deal with the administration.
If you are running your freelance business from abroad, then nothing prevents you from taking contracts with French clients. Such international collaborations are done all the time via freelancing sites (Again, there are quite a few sites for developers that require knowing French and being registered as an autoentrepreneur in France - they simply demand your SIREN number when registering.)