You can indeed, and countries do indeed have laws governing this, as does Romania[1]. The sources of spending for electoral ads have to be very transparent, and adhere to various regulations, such as that foreign governments, institutions and companies cannot finance local elections.
[1]: https://legislatie.just.ro/Public/DetaliiDocument/73672
"International law prohibits states from intervening in the internal and external affairs of other states [...] as coercion-as-control, an action materially depriving the victim state of its ability to control its sovereign choices. This may be done even through acts like cyber operations that the victim state is entirely unaware of." [1]
[1]: https://www.cambridge.org/core/services/aop-cambridge-core/c...