Brain-Machine Interfaces (BMIs) are systems which mediate communication between brains and artificial devices. Their long term goal is to restore motor functions, and this ultimately demands the development of a new generation of bidirectional brain-machine interfaces establishing a two-way brain-world communication channel, by both decoding motor commands from neural activity and providing feedback to the brain by electrical stimulation. Taking inspiration from how the spinal cord of vertebrates mediates communication between the brain and the limbs, here we present a model of a bidirectional brain-machine interface that interacts with a dynamical system by generating a control policy in the form of a force field. In our model, bidirectional communication takes place via two elements: (a) a motor interface decoding activities recorded from a motor cortical area, and (b) a sensory interface encoding the state of the controlled device into electrical stimuli delivered to a somatosensory area. We propose a specific mathematical model of the sensory and motor interfaces guiding a point mass moving in a viscous medium, and we demonstrate its performance by testing it on realistically simulated neural responses.