# keys.sh - give the sandbox a key that it can use but cannot read.
# 1. Describe the pretend API to the gateway, and hand over its key.
openshell profile import -f notes_api.yaml
NOTES_API_KEY=kru-1234-this-is-the-real-key \
  openshell provider create --name notes --type notes-api --credential NOTES_API_KEY

# 2. Start the pretend API here, outside the sandbox. It writes what it sees to a file.
python3 key_server.py > key_server_seen.txt 2>&1 &

# 3. Attach the key to the running sandbox, and put the small agent inside.
openshell sandbox provider attach demo notes --wait
openshell sandbox upload demo fetch_notes.py

# 4. Inside the sandbox: what is the key, and does it work?
openshell sandbox exec -n demo -- python3 fetch_notes.py

# 5. From out here, with a guess for a key. The pretend API is strict.
curl -sS -H "Authorization: Bearer my-guess" http://127.0.0.1:8642/notes

# 6. Outside the sandbox: what did the pretend API see?
cat key_server_seen.txt

# 7. Inside again: carry the same key to another address that Python may reach.
openshell sandbox exec -n demo -- python3 fetch_notes.py https://api.github.com/zen
