In IoT environments, various applications and protocols rely on spatial query processing to obtain, analyze, and interpret information from sensor nodes based on their location within a specific area. It enables the efficient monitoring and management of spatial data, which is crucial for applications such as environmental monitoring, smart cities, and disaster response. By querying the location and status of sensor nodes, spatial query processing facilitates real-time decision-making, optimizes resource allocation, and enhances the overall performance of the IoT system.This paper focuses on Window queries, a key spatial query type that retrieves data from sensors within a defined two-dimensional zone. The research aims to improve spatial query processing in IoT environments by proposing a Window query processing method that balances various performance factors such as energy efficiency, latency, accuracy, and query success rate. We introduce a novel approach using mobile agents to enhance spatial query processing by addressing the constraints of sensor networks. Simulation results from the NS-2 simulator demonstrate the effectiveness of our method across different parameters and environments.