Salamanders are capable of a variety of locomotor behaviors including swimming, underwater stepping, and forward and backward land stepping. According to electromyographic and kinematic recordings of the trunk, each of these behaviors is characterized by a pattern of muscle activation and body curvature with specific values of cycle duration and trunk intersegmental phase lag. A wider, continuous range of intersegmental phase lags is also observed in recordings of isolated spinal cords. Previous models have typically been limited to the generation of two stereotypical behaviors and transitions between them. In contrast, the present work specifically addresses the flexibility of the spinal cord locomotor networks. We investigate how a flexible central pattern generator (CPG) can be modulated by a higher regulation mechanism to generate appropriate patterns of muscle activation. We then look at the effect of the muscles properties and interactions with the environment on the kinematic pattern, and how local proprioceptive feedback can shape the CPG activity. We propose a CPG model based on abstract oscillators that reproduces the main features of recordings from isolated spinal cords, and that scales well to the higher frequencies of locomotion in the intact animal. The model reproduces the distribution of intersegmental phase lags, the correlation between phase lags and cycle frequencies, and the spontaneous switches between slow and fast rhythms. Using numerical simulations of a salamander robot with a simple muscle model and proprioceptive sensory feedback, we show that the CPG model can reproduce the different motor behaviors of the animal. We find that local proprioceptive feedback, together with the mechanical properties of the muscles, can play an important role in reducing the variability of intersegmental phase lags towards values appropriate for locomotion. To validate the simulation results in the real world, we implement the CPG model as a completely distributed controller on a salamander robot. We show that the animal behaviors can be reproduced using only two simple drive signals and local sensory feedback. We find that local proprioceptive sensory feedback can reduce or replace the need for different levels of drive. In particular, good swimming gaits are achieved with the robot using only one level of drive by introducing a strong proprioceptive feedback in the axial oscillators. The model suggests that the same principles govern the shaping of the motor pattern by descending drive signals and local sensory feedback.