The answer depends on the reason for the bag.
If the anus and rectum have been removed, then it is extremely difficult.
People have done reconstructions in the past but the results were often terrible because nothing can really replace an anal sphincter.
It is such a complex structure that can selectively allow passage of gas without soiling when working perfectly. The reconstructions in the past have often resulted either in difficulty with evacuation or incontinence or under both.