A court in Riyadh handed down the sentences. The case involves 32 people, including 30 Saudis, one Iranian and one Afghan national.
Saudi state media reported in February that those charged were accused of establishing a spy ring in collaboration with Iranian intelligence and providing Iran with highly sensitive information on the Saudi military.
The reports said they also were charged with seeking to commit acts of sabotage against Saudi economic interests, inciting sectarian strife, recruiting others for espionage and participating in anti-government protests.