How to attach a field to an entity programmatically?
Yes, it is possible, the function is field_create_instance().
If the field was not created before, you will need to create it with field_create_field() first.