You can do it by inserting the characters into the keyboard buffer, and then returning back to BASIC. (You can also do it by programming a soft key with *KEY, and then inserting just that into the keyboard buffer, but this won't work if you have something valuable between &B00 and &BFF).
Here's an example:
Code:
\ insert command into keyboard buffer, character by character
LDX #0
.insertloop
TXA
PHA
LDA #138
LDY command,X
LDX #0
JSR &FFF4
PLA
TAX
INX
CPX #commandend-command
BNE insertloop
\ turn off VDU output (otherwise you'll see the commands being 'typed' into the keyboard buffer)
LDA #21
JSR &FFEE
\ enter BASIC
\ note: if the machine code was definitely called from BASIC, you can just put an RTS instead
LDX #basic MOD 256
LDY #basic DIV 256
JMP &FFF7
.command
\ abbreviated as much as possible, to avoid filling up the keyboard buffer
EQUS "PA.=&2E00"
EQUB 13
EQUS "O."
EQUB 13
EQUS "RUN"
EQUB 6 \ reenable VDU output just before 'pressing' RETURN
EQUB 13
.commandend
.basic
EQUS "BASIC"
EQUB 13
Untested, but should do the trick!