as far as i know, and this would probably be valid for almost all major countries and not only spain in general sense :
- you will need a normal work permit to be able to work - the act of working is engaging in activity which brings income - so, it doesnt matter whether you are working remotely for a company outside spain or not, if you are doing an activity that allows you to gather income, you are basically ‘working’ normally. therefore, you would need a work permit, and be obliged to undertake whatever responsibilities anyone working has to. (taxes etc).
- taxes will be a question - if the company you are working for, is paying taxes for you in that remote country (it shouldnt technically) OR, if you are somehow being taxed for your income in that country, then you should be able to show that tax in spain, and reduce or negate the income tax you would need to pay in spain. but for that, the country you are getting taxed at would need to have a treaty with spain to prevent double taxation. most major countries have these with each other.
- even if you show that you are already paying tax, and got exempt from income tax, you would still need to take care of any fees/taxes/dues whatsoever necessary as someone who is earning an income in spain.
A solution would be to register as self-employed, and pay your taxes over this, if you are not being taxed in your country of origin/company origin. then you would pay your taxes in spain, be entitled to unemployment etc over the taxes you pay and so on. this seems to be the best option.