The Guardian reports that Spain is considering a "digital nomad" visa for remote, non-EU workers. https://www.theguardian.com/world/2022/sep/25/spain-plans-digital-nomad-visa-scheme-to-attract-remote-workers
A number of EU countries already have these. I think the theory is, better to have them "in-Country" spending money and be able to tax them, without having to create jobs.
At my old company, a significant share of the workforce is now permanently "remote" but due to tax and security reasons, would not allow me (if not retired) to work remotely in Spain, or any foreign country, full time.
Just beware of the "wealth tax" than many regions of Spain impose. (Kind of depends what assets you have, worldwide, whether this would effect you.) Madrid does not have one, all the rest of Spain does (although Andalucia is thinking about getting rid of theirs).