Article 108 [source]

Spanish Criminal Code
English translation

1. If the individual is a foreign national not legally resident in Spain, the judge or court shall order, in the judgment, after hearing the individual, their expulsion from the national territory as a substitute for any applicable security measures, unless the judge or court, after hearing the Public Prosecutor, exceptionally and with due justification, determines that the nature of the offense warrants serving the sentence in Spain.

The expulsion thus ordered shall entail the dismissal of any administrative proceedings aimed at granting authorization to reside or work in Spain.

If, after the order to substitute the security measure with expulsion, the expulsion cannot be carried out, the originally imposed security measure shall be enforced.

2. The foreign national may not return to Spain for a period of 10 years from the date of their expulsion.

3. Any foreigner who attempts to violate a judicial decision of expulsion and prohibition of entry referred to in the preceding paragraphs shall be returned by the government authority, and the entire period of prohibition of entry shall begin to run again.