Advances in sensor and wireless technologies will enable thousands, or even millions of small but smart sensors to be deployed for a wide range of monitoring applications. The sensor networks must be dynamically configurable and adaptive in order to response actively to events. Security must also be built into sensor networks at the very initial design stage to prevent any potential threats. This paper presents a design of a generic software architecture based on tiny active agents for sensor networks. The architecture has built-in security components. This architecture will significantly benefit the dynamic and secure deployment and configuration tasks of large sensor networks for various applications.