Create a policy
Create an egress policy in the kagent UI and attach it to an agent, so that the agent can call an external API.
About this tutorial
An agent runs in a sandbox that cannot reach arbitrary hosts. It can always reach its model and its registered MCP servers. For any other HTTP or HTTPS host, you list the host in an egress policy, and attach the policy to the agent. In this tutorial, you allow an agent to reach the GitHub API, as you would for an agent that reads issues or pull requests.
For how the egress gateway enforces a policy, see Egress policies and Core concepts.
Time: about 5 minutes.
Before you begin
- Complete Build an agent, so that you have an agent to attach the policy to. The steps use its
personal-assistantagent. Any agent works.
Allow the agent to reach GitHub
Follow the steps in the kagent UI, or apply the same resources as YAML from the command line.
Open the kagent UI
kagent dashboardThe command forwards the UI to http://localhost:8082 and opens it in your browser. Leave it running while you work.
Create the policy

In the sidebar, click Policies, and then click Create egress policy.
In the Name field, enter
github-api. Leave the Namespace askagent.Under Destination 1, in the Origin field, enter
https://api.github.com. An origin is a scheme, a host, and an optional port, without a path. A value such ashttps://*.example.commatches one level of subdomain.Leave Authentication set to None. To have the gateway add a credential to each request, so that the agent never sees it, choose Secret key instead.
Click Create policy. The page of the policy lists its destinations and, under Used by, the agents that list it.
Attach the policy to your agent
In the sidebar, click Agents. In the row of the
personal-assistantagent, click the edit icon.From the Egress policies list at the end of the form, choose
github-api.Click Save agent, and wait for the agent to return to Ready.
The agent can now send requests to https://api.github.com. Requests to hosts that no policy lists are still blocked.
Verify the policy
Check that kagent applied the policy to the agent.
kubectl get agent personal-assistant -n kagent \ -o jsonpath='{range .status.conditions[?(@.type=="EgressPoliciesApplied")]}{.status} {.reason}: {.message}{end}'Example output:
True Applied: All requested egress grants are admittedCheck that the agent is ready.
kubectl get agent personal-assistant -n kagentThe
READYcolumn showsTrue.
What you built
An agent that can reach one external API, while every other host stays blocked. Along the way, you used these features:
| Feature | What you did | Read more |
|---|---|---|
| Egress policies | Listed an origin that agents may reach | Egress policies |
| Agent egress references | Attached the policy to one agent | Egress policies |
Clean up
Detach the policy from the agent. In the kagent UI, edit
personal-assistant, cleargithub-apifrom the Egress policies list, and click Save agent. If you applied the YAML, reapply the agent withoutegressPolicyRefs.Delete the policy.
kubectl delete egresspolicy github-api -n kagent