Last month, "Wannacry," a huge ransomware attack linked to North Korea, wreaked global havoc after crippling computer networks at companies and government agencies worldwide.
EU foreign ministers meeting in Luxembourg said the 28- nation bloc was "concerned by the increased ability and willingness of state and nonstate actors to pursue their objectives through malicious cyber activities."
"Such activities may constitute wrongful acts under international law and could give rise to a joint EU response" which could include "restrictive measures" or sanctions, a statement said.
It was a major theme in last year's US presidential campaign, with Moscow accused of trying to swing the vote in favour of Donald Trump, and fears have been voiced over what might happen in German elections in September.