Espionage in Grepolis is the act of spying on an enemy city to see troop counts and building levels. This is often used to find out whether a city is worth conquering or to calculate your chances against that city's defense. You do not have to build the spy like other troops, he is more like a free agent who you pay to work for you.
The building needed to carry out an espionage is the cave. It is here that you will store silver, the higher the level of the cave, the more silver you can store (level 10 is the highest level and it allows you to store infinite silver). You will want to keep as much silver here as possible since this is also what prevents enemy espionage succeeding in your city.
The main box allows you to store silver here either with the slider or using the button to select all the silver in your warehouse, once you have stored it here, you cannot put it back in the warehouse. There is also a list of the most recent espionage reports from all your cities.
Sending a spy
In order to send a spy, you must first have at least 1000 silver in your cave. Find the city you want to spy on, click on it and find the espionage tab (a hooded figure). Here you will find a slider allowing you to choose how much silver you want to spend on this mission. There are also buttons allowing you to quickly choose either 1000 (the lowest possible amount) or all the silver in your cave, whatever that may be. It also shows how long the spy will take to reach the city. A picture will appear in your city overview side bar telling you that you currently have a espionage mission running.
In order for the espionage to be successful, you must pay more silver than the enemy city has in their cave. You only need to send 1 more silver then their cave has to succeed, so it is unadvisable to send spies with round numbers like 5000.
If you succeed then you will recieve a report showing all the enemies troops and building levels in the city but the enemy will not know that you spied on them and the silver in their cave will not be depleted. If you fail then both you and your enemy will recieve reports that you failed and their cave will lose silver equal to the silver you spend on the mission. Therefore sometimes you just need to send one more espionage attempt to be successful.
Please note that you CANNOT refill your cave while an espionage is being sent to a target.
Defending against espionage
In order to defend against attempts to spy on your city, you just have to keep your cave stocked up with as much silver as possible. Since the enemy spy will need more silver than is in your cave, having a level 10 cave and constantly adding more silver is essential. It is normal in the mid to late game that players will have silver in the millions stored in their caves.
If an enemy espionage attempt fails in your city, you will get a report and will thus know that they are interested in it. If they succeed, you will not get a report and your silver will not be depleted. This gives the enemy the element of surprise when they attack.
By researching cryptography, you can also make it 20% harder for enemy spies to carry out espionage in your city.
By building the special building oracle, you will be able to see when people have spied on you successfully, thus you will know that they are interested in your city and you can prepare for it (Note, they will be able to see that you have an oracle in their report and so they will know that you know).
Reports will come straight to your reports folder, but you can also view the most recent ones in your cave.
There are also two buttons at the bottom of the report; Simulation and Publication. The simulation button will insert the cities troops and wall level (as well as the Tower if they have it) into the simulator as defending troops to allow you to quickly determine whether your troops could clear the city. The report, however, doesn't tell you if they have researched phalanx or battering ram, nor whether they have activated commander, captain or high priestess.
The publication button allows you publish the report for other to see. You can choose to allow your troops to be seen or not, as well as defending troops and booty. All you have to do is save the report, copy the code which appears and paste it into a message or the in-game forum.
A few clarifications
Player A has 10,000 silver in their cave. Player B sends a 6,000 silver spy to their city. The spy fails as Player A has more than 6,000 silver in their cave.
Player B does not see what Player A has in their city. Player A will received a report saying that player B has attempted to spy on them. Player A's cave will now have 4,000 silver left.