Can a company registered in Germany hire a remote worker based in Iran? What regulation act is applied in this case?
If by "hire a worker" you mean hire you as their employee, then no. And that has nothing to do with Iran or sanctions.
See https://expatriates.stackexchange.com/questions/23844/can-i-work-remotely-for-a-german-company-from-india-being-an-indian-citizen and just replace "India" with "Iran", or really "any non-EU country".
The only way you can legally sell your work and get money from a German company in Germany when you don't reside in Germany with a German work permit is being an independent contractor or company and invoicing the German company for services provided.
Whether this contract would be targetted by sanctions is a matter of that specific contract. It might depend on what work you do, and what you need to be given access to, while you work.
That said, what a company legally "can do" might still not be what they do. Hiring a lawyer to navigate this (because people on the internet are not the best source of legal advice) might well exceed any benefits they have from hiring you. Even if it is legal in the end, it might still be too costly.
Your best bet here is a company that already has dealing with contractors from Iran, already has lawyers for this on payroll and knows how to navigate this legally, not only in theory, but with their specific business dealings and services.
In case you are actually asking on behalf of the Germany company, you should already know all this. You should also know that the real answer is "get a lawyer". But just in case you are just curious and want a sneak peek, you can go to the website of the "Bundesamt für Wirtschaft und Ausfuhrkontrolle" and see what they say and how your specific company and the specific contract you have in mind plays with the regulations. Warning: there is no easy answer I could summarize here, it is multiple pages of references to applicable laws and regulations.
If your company has dealing with other nations, especially the US, you may want to check their conditions as well. Even though it might be legal in Germany, that does not really give you any protection from other countries sanctioning you in their juristiction or simply not giving you any further contracts because you don't play by their rules.
I think you should rephrase your answer slightly, because the OP doesn't specify whether he's the potential hire or representing the company that wants to hire.– PMFJan 4 at 12:00
@PMF thanks, added a part about that.– nvoigtJan 4 at 12:10
3I wouldn't be so categorical on "The only way you can legally sell your work and get money from a German company in Germany when you don't reside in Germany with a German work permit is being an independent contractor or company and invoicing the German company for services provided." Hundreds of thousands of people reside in neighbouring countries but are employed by German companies. And this is not just an EU thing, it also happens between FR and CH for instance. But it can be a very complex situation, and usually requires bilateral agreements to handle taxation, social security, etc.– jcaronJan 5 at 0:13
1And yes, it is quite common especially for companies near the border to have employees, either German or not, living in a neighbouring country. Often not remote working but commuting. I'd bet you can find someone who actually walks to and from work from a foreign country. Jan 5 at 12:05
1@gnasher729 Commuting is in fact a requirement under some cross-border agreements, e.g. with Switzerland, to prevent businesses from shopping around for their preferred legal system. This was an issue when Covid forced some cross-border workers to stay at home.– RelaxedJan 5 at 15:43
In addition to nvoigt's answer, it's worth mentioning that there are many things which may not be allowed to be performed by people in Iran by regulation or due to existing contracts with customers or suppliers.
For some, it's the simple fact that a person is not in the EU which may be an issue, for instance if there is any access to personal data protected by GDPR, any transfer of the data to or access to the data from outside the EU can be problematic.
For others, it may be related to export regulations preventing sensitive material (lots of electronics, computer hardware and software) to countries subject to sanctions.
Even if the company itself is not affected directly, some customers (especially the larger ones) may require the company to ensure and certify that everything is done in the EU, with no employees or subcontractors outside the EU, much less in sanctioned countries.
This closes the door to a lot of possible activities.
2It may also be difficult for the person to get paid?– gerritJan 5 at 11:56