In other words - is the "illegality" of an action restrained to a
country, from that country perspective? Or does performing this action
abroad (where it is legal) does not matter?
Sometimes yes. It depends on the nature of the act.
It depends. One of the most important questions is whether the actions taken abroad were directed at legally protectable interests of the country seeking to prosecute them.
For example, the U.S. imposes income taxes on all of the worldwide income of its citizens, and some things that count as income in the U.S. are tax free in other countries that, for example, don't have an income tax. The U.S. can still prosecute someone for no reporting or paying tax on that income.
Another example would be material support of terrorism. If the State Department has determined than an organization engaged in terrorist acts agains the U.S. or its interest, giving money to that organization while abroad can be prosecuted in the U.S., even if it is legal to give money to the organization in the country where the gift took place. 18 U.S.C. Sections 2339A and 2339B.
In both circumstances, the idea is that the foreign conduct which is legal abroad has an impact on and connection to the prosecuting country that it has a legitimate interest in regulating.
Authority And Ability To Enforce Are To Different Things
Of course, there is the very practical question of how a violation of a domestic law in a foreign country can be enforced, though some pretty extreme tools are tolerated.
For example, the U.S. Supreme Court upheld the prosecution of a Mexican national who was kidnapped in Mexico by U.S. agents and brought back to a U.S. court to be prosecuted, despite the fact that there is an extradition treaty in place with Mexico which wasn't used, for kidnapping and murdering a U.S. DEA agent and a pilot (who was not a U.S. citizen or direct U.S. employee) who was working with the DEA agent, actions that took place entirely in Mexico (and in that case also violated Mexican law). United States v. Alvarez, 504 U.S. 655 (1992).
But, often arresting someone, or enforcing a judgment against someone who is currently abroad, or proving that the law was violated abroad from an evidentiary perspective in a way that holds up in court, is very difficult.
Comity v. Full Faith and Credit
Notably, under U.S. law, even when U.S. courts, for example, respect the validity of a foreign court's legal judgment or a foreign legal act (such as a marriage), more carefully written legal opinions note that they do so out of "comity" and respect for a foreign legal system, rather than because a U.S. court is required by the constitution or a treaty or any other principle other than voluntarily adopted court precedents that could be changed by statute or future court decisions, to honor them.
In contrast, between U.S. states, the principle of "full faith and credit" in the U.S. Constitution, means that the courts of one state are required by the constitution to honor foreign legal decision and acts, subject only to narrow exceptions.
Normally, this is completely dependent upon the law of the prosecuting country.
In rare cases, if the prosecuting country is a party to a treaty, that treaty is considered as a binding part of the prosecuting country's laws.
For example perhaps a tax treaty between the city-state of Monaco (which is known for its casinos) and the U.S., duly ratified by the U.S. Senate, provides that the U.S. agrees not to impose U.S. income taxes on gambling winnings won in Monaco, notwithstanding general principles of U.S. tax law. This would remove the authority of the U.S. to prosecute a U.S. citizen for not paying tax on this part of their worldwide income including foreign income which is not taxable abroad, which would otherwise exist under U.S. law.
There is not such thing in reality as commonly agreed upon international law, although sometimes it is claimed to exist as a legal fiction in a stylized way as part of how diplomats and lawyers and judges in the domestic courts of a country talk about how international legal situations should be treated by a country.
Some treaties (such as those in connection with the EU and Council of Europe, which handles European human rights, and a handful of UN Treaties, such as those related to intellectual property and child custody) do comprehensively resolve jurisdictional issues in some particular subject matter and do have a great many signatories who are bound by them. But, this situation is largely the exception rather than the rule.
There are a few tribunals that enforce treaties independent of the domestic legal system of the parties to the treaty (e.g. the International Criminal Court). But, they impose sanctions based upon obligations arising from or acknowledged in the treaty, rather than arising from the domestic law of a treaty member for something that was illegal under the domestic law of another treaty member.
There is also out there and recognized by a few countries, the notion of "universal jurisdiction" under which certain acts (basically war crimes and similarly grave offenses) are so bad that the country's courts allow their courts to be used to punish these offenders even if none of the acts involved and none of the parties involved had any connection to the country where the courts are located at all, on that theory that these acts harmed all of humanity including its citizens.