Wireless sensor networks are composed of large numbers of tiny networked devices that communicate untethered. In this paper we present the design of Contiki, a lightweight and portable operating system for such tiny devices. In this work, we try to find the right operating system abstractions that enable dynamic and efficient operation of a system with severe limitations. Contiki is built around a lightweight event scheduler and provides suitable abstractions for dynamic loading of programs, device drivers, and run-time linking of libraries. The system is highly portable and the kernel can be ported without changing a single line of code (except device drivers). We show how higher level abstractions such as multi-threading can be implemented as libraries on top of the lightweight event kernel.