Let $X$ be the set of functions from $\mathbb R$ to $\mathbb R$ that have antiderivatives on all of $\mathbb R.$
Claim: There exists $f\in X$ such that $f^n\notin X$ for $n=2,3,\cdots.$ (Here $f^n$ is the $n$th power of $f,$ not the $n$th iterate.) This addresses both the product question and the composition question. If the claim is true, then $f\in X$ but the product $f\cdot f \notin X.$ Also, with $g_n(x) = x^n, n = 2,3, \dots,$ we see $g_n\circ f\notin X$ even though the $g_n$'s are very nice and $f\in X.$
The following lemma will be helpful:
Lemma: Suppose $f:\mathbb R\to \mathbb R,$ with $f=0$ on $(-\infty,0]$ and $f$ continuous on $(0,\infty).$ Then $f\in X$ iff $\int_0^x f$ converges for all $x>0$ and
$$\lim_{x\to 0^+}\frac{1}{x} \int_0^x f = 0.$$
Here the convergence of $\int_0^x f$ is in the improper integral sense, meaning $\int_0^x f = \lim_{a\to 0^+}\int_a^xf$ assuming the limit is finite.
Proof: $\implies:$ Let $f\in X,$ with $F'=f$ on $\mathbb R.$ Let $x>0.$ For any $a\in (0,x),$ $F\in C^1[a,x].$ Thus
$$\tag 1 F(x)-F(a) = \int_a^x f.$$
As $a\to 0^+,$ the left side of $(1)$ $\to F(x) - F(0)$ by the continuity of $F.$ It follows that the right side has a finite limit, hence $\int_0^x f$ converges. Note that we have shown
$$F(x)-F(0) = \int_0^x f.$$
Now $F'(0) = f(0)= 0.$ It follows that
$$0 = \lim_{x\to 0+}\frac{F(x)-F(0)}{x-0}= \lim_{x\to 0+} \frac{\int_0^x f}{x}$$
as desired.
$\impliedby:$ Simply define $F(x) = \int_0^x f.$ By the continuity of $f$ on $\mathbb R\setminus \{0\},$ we have $F'(x) = f(x)$ for $x\ne 0.$ At $0,$ we easily see the derivative from the left of $F$ at $0$ is $0.$ From the right we have
$$\lim_{x\to 0+}\frac{F(x)-F(0)}{x-0}= \lim_{x\to 0+} \frac{\int_0^x f}{x} = 0.$$
This shows $f\in X$ and the proof of the lemma is complete.
Proof of the claim: We build a slightly crazy $f\in X.$ For $n=2,3,\dots$ let $a_n = 1/n, b_n = 1/n + 1/2^n.$ Then the intervals $[a_n,b_n]$ are pairwise disjoint.
On each $[a_n,b_n]$ let $f$ be an isoceles triangular spike from the end points of height $2^n/n^3.$ Define $f =0$ everywhere else. Then $f$ satisfies the hypotheses of the lemma. Now
$$\int_0^1 f = \sum_{n=2}^{\infty} \frac{1}{2}\cdot \frac{1}{2^{n+1}}\cdot \frac{2^n}{n^3} = \sum_{n=2}^{\infty} \frac{1}{4n^3} <\infty.$$
To show $(1/x)\int_0^x f \to 0,$ suppose $x\in [a_n,a_{n-1}].$ Then
$$\tag 2 \frac{1}{x}\int_0^x f \le \frac{1}{a_n}\int_0^{a_{n-1}}f = n \sum_{k=n}^{\infty}\frac{1}{4n^3}.$$
The last sum is $O(1/n^2).$ So $(2)$ is no more than $nO(1/n^2) = O(1/n) \to 0.$ Thus the left side of $(2)\to 0$ as $x\to 0^+.$ The lemma now shows $f\in X.$
The easy part of the claim is showing higher powers of $f$ are not in $X.$ By the lemma, all we need to show is that $\int_0^1 f^2 = \infty.$ It will then follow that $\int_0^1 f^n = \infty, n=3,4,\dots $
Here's what I get (but the reader should check):
$$\int_{a_n}^{b_n} f^2 = \frac{2^n}{3n^6} .$$
Thus $\int_0^1 f^2 =\infty,$ by a mile. The proof of the claim is complete.