Debugging in distributed environments, such as wireless sensor networks (WSNs), which consist of sensor nodes with limited resources, is an iterative and occasionally laborious process for programmers. In sensor networks, it is not easy to find unintended bugs that arise during development and deployment, and that are due to a lack of visibility into the nodes and a dearth of effective debugging tools. Most sensor network debugging tools are not provided with effective facilities such as real-time tracing, remote debugging, or a GUI environment. In this paper, we present a hybrid debugging framework (HDF) that works on WSNs. This framework supports querybased monitoring and real-time tracing on sensor nodes. The monitoring supports commands to manage/ control the deployed nodes, and provides new debug commands. To do so, we devised a debugging device called a Docking Debug-Box (D2-Box), and two program agents. In addition, we provide a scalable node monitor to enable all deployed nodes for viewing. To transmit and collect their data or information reliably, all nodes are connected using a scalable node monitor applied through the Internet. Therefore, the suggested framework in theory does not increase the network traffic for debugging on WSNs, and the traffic complexity is nearly O(1).