In order to work (telecommuting) for a US-based company from another country (Spain in my case), is it necessary some kind of visa?
You may not need a visa to work from Spain, but your employer will have to register in Spain with social security and appoint a representative, as they will have to provide for your SS coverage. As a Spanish worker in Spain, both you and your employer must comply with Spanish regulations. Make sure they are OK with that before you commit to them.
Edit (as per Peter K comment) Please note that this answer is only relevant if you are an employee, not a self employed contractor.
If they hire you as a contractor (not a regular employee of theirs), there is absolutely no issue. If they are hiring you as an employee, and you never set foot in the US, I think you are OK as well (but their HR department will know the answer to that definitively, and also work with you to obtain the necessary permissions).
The company may have security issues (depending on what their business is) giving you access to their networks since you are a non-US Person, but that doesn't have anything to do with visas.