We consider the problem of implementing a security protocol in such a manner that secrecy of sensitive data is not jeopardized. The implementation is assumed to take place in the context of a language named Join Voyagers used to program a Peer-to-Peer network using object oriented techniques and Join methods. A mobile agent is an object that can migrate throughout a heterogeneous network of computers, under its own control, in order to perform tasks using resources of these nodes.We develop a basic architecture to express security protocols for communication and strong migration, or to enforce cryptographic primitives based on SPI calculus. These protocols rely on cryptography and on communication channels with properties like authenticity and privacy.This article will present also a series of aspects related to mobile code security, namely the protection of hosts receiving a malicious code and the protection of a mobile code within a malicious host from our programmable Peer-to-Peer network.