It’s a common trope in Ottoman-related novels, fanfics and TV series that an Austrian/Venetian/Persian spy was just in the palace. Did Habsburgs, Venetians, Persians and other countries hostile to the Ottomans develop secret agents and spies from among the eunuchs and concubines?
I'll try to answer your question
Yes, the Habsburgs and primarily the Venetians did make contact and turn figures inside the palace as information-brokers (or spies). This includes eunuchs, members of the harem, and military grandees. During this period, information was relatively fluid, and spies who had access to private or inner circles of governments were extensively used by both sides. Just as there were Habsburg informants in the Ottoman palace, there also were Ottoman agents in the Habsburg court.
Gazanfer Agha, the powerful Chief White Eunuch of the Palace was such an example. Gazanfer, originally a Venetian maintained contact with the Venetian baili, the ambassador; He even agreed in 1594 to a secret face-to-face meeting with baili Marco Venier inside the imperial palace. Additionally, Gazanfer's sister, Beatrice Michiel or Safiye Hatun also became an information-broker for the Venetians. She not only frequently defended Venetian interests in front of the Valide Sultan, but also encouraged her brother, who was usually careful not to be seen as too pro-Venetian, to act in accordance with Venice’s interests. Ömer Agha, the protege of Gazanfer were also in contact with the Venetians.
Safiye Sultan, the wife of Sultan Mehmed III communicated with the Austrian ambassador via her Jewish kira, a female servant of the harem, and kept him informed of Ottoman military preparations on the eve of the War of 1593-1606. She also advocated for Venetian interests and kept in contact with Venetian officials. Gregorio Bregante or Murad Agha, a eunuch and cavalry commander was also a Habsburg informant who delivered news about the Ottoman arsenal and aided other Habsburg spies.
The motivation and reason behind these people's subversive activities varied. Most usually did it because they still had attachment or investments in their former country or identity, in something that Metin Kunt called ethnic-regional solidarities or cins. For example, Gazanfer Agha and Safiye Hatun requested privileges and exceptional favours for their relatives back in Venice. Many just did it for the money. Safiye Sultan's kira were paid handsomely by the Venetians, and Gregorio Bregante were regularly paid by the Austrians to do their bidding.
Sources/Recommended Reading:
Espionage In The 16th Century Mediterranean: Secret Diplomacy, Mediterranean Go-Betweens and The Ottoman-Habsburg Rivalry by Emrah Safa Gürkan
Mediating Boundaries: Mediterranean Go-Betweens and Cross-Confessional Diplomacy in Constantinople, 1560-1600 by Emrah Safa Gürkan
The Sultan’s Renegades: Christian-European Converts to Islam and the Making of the Ottoman Elite, 1575–1610 by Tobias P. Graf