On this page5 sections
You ask your coding agent to grab a YouTube video, pull a transcript, or test the "import from URL" feature it just wrote. On your laptop it works. Run the same task in a cloud sandbox (Claude Code on the web, OpenAI Codex cloud, Cursor background agents, a GitHub Actions job, or the backend of an app you built in Replit or Lovable) and it fails with something like:
ERROR: [youtube] VIDEO_ID: Sign in to confirm you're not a bot.or HTTP Error 403: Forbidden, or a transcript library that comes back empty. The agent will usually try a few fixes, update its downloader, and then tell you the video "may be restricted". It isn't. The problem is where the agent is running.
Two walls between a sandbox and a video
Wall 1: the sandbox's own network rules
Cloud agents run with limited internet access by default, and video sites aren't on the list.
- Claude Code on the web: a new environment starts at Limited network access, which allows package registries, GitHub and cloud SDKs, plus domains you add. YouTube isn't on the default list, so the request is refused with a
403andx-deny-reason: host_not_allowedbefore it reaches YouTube (Anthropic's docs). - Codex cloud: "By default, Codex blocks internet access during the agent phase." Setup scripts still get internet access, and you can turn it on per environment with a domain allowlist (OpenAI's docs).
If the sandbox itself refused the request, nothing you change in the download command will help. That's a setting, and you can change it.
Wall 2: the video site blocks datacenter IPs
Open the network up and you hit the harder wall. Cloud sandboxes, CI runners and serverless backends all run on datacenter IP ranges, and YouTube and other large platforms treat a lot of that traffic as bots. That's where "Sign in to confirm you're not a bot", 403s on the media URLs, and empty or blocked transcripts come from. Your laptop is on a home connection, so the same command works there.
Two smaller things make it worse in a fresh sandbox: the agent often installs whatever downloader version the package manager has (sites change often, and older versions break), and the common open-source downloaders now need a JavaScript runtime for YouTube that a minimal container may not have. Fixing those is worth doing, but it doesn't change the IP.
The free options, and where they stop
These are worth trying first, and for a lot of people one of them is enough.
- Run the media step locally. If you need one video or one transcript for development, run that step on your own machine (or with the agent's local CLI) and commit the file or a fixture. For tests, a small sample file in the repo is better than a live download anyway: it's fast and it won't flake.
- Allow the domains. On Claude Code on the web or Codex you can add YouTube's hosts to the environment's allowlist. That gets you past wall 1. You'll still be on a datacenter IP for wall 2, so expect it to work sometimes and fail often.
- Pass browser cookies. Exporting cookies from a logged-in browser can get you past the bot check for a while. The catch: you're putting a logged-in session into a sandbox the agent can read, the account can get flagged, and cookies expire. It also doesn't change the IP. The cookies guide on ytdlp.org covers how and the risks.
- Use your own machine as the runner. For CI, a self-hosted runner on a home or office connection avoids the datacenter IP. It's also a machine you now maintain. There's a full walkthrough in the GitHub Actions guide and a first-person version on dev.to.
- Use the official API where there is one. The YouTube Data API is good for titles, durations and thumbnails. It doesn't give you the video file, and caption downloads are limited to videos you have edit access to (Google's docs).
The real question: where will this run in production?
If the agent is building something (an app that imports videos from a link, a pipeline that transcribes uploads, a tool that reads metadata), the sandbox failure is a preview. The app will run on a server, and the server is on a datacenter IP too. The same block that stopped the agent will stop your users' imports, usually after launch and usually without a clear error. The server guide and the transcripts on cloud IPs guide go into why.
So the useful fix isn't getting one download through the sandbox. It's having the app call something that works from servers.
Build it on the Importly API
Importly turns any video or audio link into files, transcripts and metadata with one API call, and it works from servers, CI and agent sandboxes. Your app sends the link and gets a webhook with a link to the file:
curl -X POST https://api.importly.io/import \
-H "Authorization: Bearer $IMPORTLY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://www.youtube.com/watch?v=VIDEO_ID",
"webhookUrl": "https://your-app.com/webhooks/importly"
}'Transcripts work the same way with POST /transcribe, and if the video has no captions, speech-to-text runs on the same URL. Results can go straight to your own S3 or R2 bucket.
Your agent can set this up for you. Connect the Importly MCP server to Claude Code, Codex or Cursor with your API key, then ask it something like "Add import-from-URL to our upload form using Importly". It reads the integration guide for your stack and writes the server route, the webhook handler and a polling fallback, with the same key your app will use (build with your agent).
In a locked-down sandbox, that means one host to allow, api.importly.io, instead of opening the environment up to video sites and hoping the IP isn't flagged. And when the code ships, it keeps working on your server for the same reason.
New accounts get $3.00 in free credit with no card, which is enough to test with real links from your real environment. Start with the quick start, or see how it fits apps built with AI tools.
FAQ
Why does Claude Code download the video on my laptop but not on the web?
Claude Code on the web runs in a cloud environment with a network allowlist that doesn't include YouTube by default, and even with it allowed, the request comes from a datacenter IP that YouTube often treats as a bot. On your laptop, it's your home connection.
Is "Sign in to confirm you're not a bot" a bug in my code?
Usually not. If the same command works locally and fails in the sandbox or on a server, it's the IP. Check for a stale downloader version and a missing JavaScript runtime, but don't expect those to fix it on their own.
Can I just give the agent my YouTube cookies?
You can, but the agent and anything it runs can read them, the account can get flagged, and they expire. For a one-off, running the step on your laptop is safer.
Does my agent need Importly to download a video for me?
No. For a quick one-off, run it locally. Importly is for when the download has to happen in your app or pipeline, on a server, where you can't run it from your laptop.
Related: Hosted API vs self-hosting a downloader, Serverless video download, YouTube downloader API, Importly docs.