my circuit is from the lm386 datasheet with 16 V source, what i amplify is 40khz arduino pwm output, is there any explanation why this happened, thanks
The waveform distinctly shows that the LM386 is not an amplifier with the bandwidth or output slew rate capable of amplifying your input waveform that has basically square edges.
The LM386 is considered to be an audio power amplifier which would mean that it would be typically capable of handling sine wave type audio frequencies from about 100Hz up to about 20kHz in a real application.
The part is speced to have a bandwidth of typically 300KHz when the gain is at its default level of 20. Of course that is for sine wave signals. At the large wave signal you are feeding you will come no where close to that.
Depending on your requirements, it may be smart to go with just a simple single-transistor switch like the one shown below:
Keep in mind that the output will be inverted! If this is a problem, you can either invert the output of the micro somehow, or add another one of the 'invertors; in. I believe it's both cheaper and probably better suited for what you intend to do than the LM386!