It's in the documentation here:
https://laravel.com/docs/9.x/sail#installing-composer-dependencies-for-existing-projects
You can use the sail Docker container on its own to bootstrap the process, and run composer in that container. The main part of that documentation is this command:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
There is a laravelsail/php7.4:latest container too, if you are not yet using PHP 8.
Edit: the above used to work, but now appears to be broken. The container does not have a sail user or group, and that leads to permission problems.
When the sail up command is executed, the entrypoint to the PHP container will take the current user ID and group ID, then assign them to the sail user and group. That happens (now) in the sail up command and not the laravelsail container listed above.
I'm not sure when this changed. For now you can run the above without the -u option, and set up the application as root within the container. Permissions will need to be manually fixed after that.
Also note the laravelsail/php7.3 container only has composer v1.8 installed initially, but is easily updated using composer self-update.