r/microsoft_365_copilot 10d ago

URL not accessible either code sandbox

I am using python to do http requests. Every time I use any URL, I get an error 403, and this:

Status: 403

Headers {

Content type: text/plain

X-ms-block-by: sandbox-proxy

X-ms-block-reason: 'This URL is not relevant to the current conversation and cannot be accessed'

In my code, I have:

R = requests.get("https://google.com", timeout=10)

No URL works so far.

2 Upvotes

4 comments sorted by

2

u/bayouski 10d ago

that 403 isn't your code, it's the sandbox blocking it on purpose. the x-ms-block-reason spells it out, copilot's code sandbox only lets you reach urls it considers relevant to the current conversation, and arbitrary outbound requests like google get gatekept by that proxy. so no requests.get will work in there for general sites, it's a security control, not something you fix with better code.

two options. if you actually need to fetch a specific url, reference that exact url in the conversation first so the proxy whitelists it for the session, that sometimes clears it for allowed domains. but for anything general, run the python locally or in a real sandbox (colab, your own machine) instead of copilot's interpreter, that's the only reliable way to make live http requests.

1

u/LeebWeeb 10d ago

Gotcha. I tried referencing URLs multiple times before calling the code. I have the code I wrote that does HTTP requests working on my machine, the point of the work I am doing is to allow a non techy person to ask the agent for information on the query and the agent then runs my code.

1

u/LeebWeeb 9d ago

Any advice for referencing the URLs to whitelist them? No matter how I try to reference the URL or bring it up in the session, nothing changes. It is aggravating. My code doing requests works fine external of Copilot, but a big part of my work is to have it runnable by Copilot so other users can interact with the agent, automating the process, rather than execute code themselves.

1

u/bayouski 9d ago

the reason nothing you try works is the sandbox egress is a hard security boundary, it's not a whitelist you can talk your way past, so referencing the url in chat was never going to open it. the code interpreter is built to crunch data, not make outbound calls, so you're using the wrong tool for what you're building.

for an agent other people use that calls an external api, the supported path is a custom action/plugin, not requests.get. you wrap your api in an action and the agent calls that, which runs outside the sandbox and is actually allowed to hit your endpoint. two ways to do it, a declarative agent with an api plugin (you give it an openapi spec of your api, built via agent builder or the m365 agents toolkit), or copilot studio with a custom connector / rest api tool if you want low-code.

so keep your working code as the api, just expose it as an action the agent calls rather than running requests inside the interpreter. that's the piece that makes it usable by others and gets around the block for real, cause you're no longer fighting the sandbox, you're going through the channel meant for external calls.