Mobile code and mobile agents are generally associated with security vulnerabilities, rather than with increased security. This paper describes an approach in which mobile agents are confined, in order to allow content providers to retain control over how their data is exported while allowing agents to search the full content of this data locally. This approach offers increased control and security compared to the traditional client-server technologies commonly used for building distributed systems. We describe a new system, called Mansion, which implements confinement of mobile agents, and describe a number of applications of the confinement model to illustrate its potential.