Modular robots have the potential to achieve a wide range of applications by reconfiguring their shapes to perform different functions. This requires robust and scalable control algorithms that can form a wide range of user-specified shapes, including shapes that adapt to the environment. Here we present a decentralized algorithm for self-organizing of environmentally- adaptive shapes. We apply it to a chain-style modular robot, configured to form a flexible sheet structure. We show that the proposed algorithm is capable of achieving a wide class of environmentally-adaptive shapes, and the module control is simple, scalable, robust and provably correct. The algorithm is also self-maintaining: the shape automatically adapts if the environment changes. Finally, we present several applications which can be achieved within this framework via robot prototypes and simulations, such as a self-balancing table. In our experiments, we demonstrate the algorithm is highly responsive and robust in the face of real-world actuation and sensing noise.