Intellect devourer is not an object
It is an aberration of tiny size.
Nothing states, that they are one and the same entity.
Note, that it is possible to save the host. Furthermore rules state about Intellect devourer leaving the host, when he drops to 0 hp. The host and the Intellect Devourer are two seperate creatures.
How will polymorph work?
While inside a creature, the intellect devourer has total cover against attacks and other effects originating outside its host.
You cannot affect the intellect devourer itself, but only the host.
True polymorph
Choose one creature or nonmagical object that you
can see within range.[...]
The only thing, you will see is once again, the host, not the intellect devourer. Accordingly, to the spell's decription, only one creature will be affected and that will be the host.
What will be the effect?
Despite the fact of being polymorphed, the host is still the same creature.
The effect will be a dog with the intellect devourer inside it's skull. Because True Polymorph usually affects mental ability scores it is possible to notice, that something is wrong, as the dog will have an Intelligence of 12, instead of 3.
The Bag would be destroyed.
The item description states:
If the bag is overloaded, pierced, or torn, it ruptures and is
destroyed, and its contents are scattered in the Astral Plane.
In this case, the bag would almost certainly become overloaded. It would rupture - and would be destroyed. The creature would be placed somewhere on the Astral Plane. The amount of damage, if any, is unspecified and would be up to the DM.
Best Answer
No, you can not attack from inside or vice versa
Rope trick specifically states (PHB, 272):
Using Miniatures
This is a bit of an easier case. The square you control and cast/attack from is the grid you are in. You can not take ownership of two separate grids unless you are a Large creature (or larger). This means that in order to cast from outside of the Rope Trick, you must absolutely leave the Rope Trick.
Theatre of the Mind
This is a bit of a trickier proposition, but the same general idea applies from Miniatures. It may seem like you can simply reach outside of it, but the text of not being able to fire from within it suggests that such a workaround isn't possible. Combine that with how grids work and it is not a viable strategy to use it as a foxhole. It's more of a bolthole to escape from, not to attack from.