For reference, the description of the Bag of Tricks says, in part (DMG, p. 154):
You can use an action to pull the fuzzy object from the bag and throw
it up to 20 feet. When the object lands, it transforms into a creature
you determine by rolling a d8 and consulting the table that
correspond's to the bag's color. See the Monster Manual for the
The creature is friendly to you and your companions, and it acts on
your turn. You can use a bonus action to command how the creature
moves and what action it takes on its next turn, or to give it general
orders, such as to attack your enemies. In the absence of such orders,
the creature acts in a fashion appropriate to its nature.
How long do creatures from a Bag of Tricks last?
As noted in daze413's answer, the description of the bag of tricks was clarified in the DMG errata in 2015 to read as follows:
The item had limitations on in previous editions, as noted below:
2nd edition time limit: 10 minutes (1 turn)
3rd edition time limit: 10 minutes
3.5e: Same as 3rd edition
4th edition time limit: 5 minutes or encounter length
Note, that in the absence of orders (one would presume continual), the animal summoned will wander off and do what is natural to it. So you could game it several ways to prevent the character from having an army of baboons or similar.