Skip to content
This documentation covers kagent while it is in development and can describe unreleased features. For the current release, see the latest docs.

Create a policy

Page as Markdown

Create an egress policy in the kagent UI and attach it to an agent, so that the agent can call an external API.

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

  1. Complete Build an agent, so that you have an agent to attach the policy to. The steps use its personal-assistant agent. 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 dashboard

The command forwards the UI to http://localhost:8082 and opens it in your browser. Leave it running while you work.

Create the policy

The kagent UI creating an egress policy named github-api and attaching it to the personal-assistant agent
Figure: Creating an egress policy and attaching it to the agent, sped up
  1. In the sidebar, click Policies, and then click Create egress policy.

  2. In the Name field, enter github-api. Leave the Namespace as kagent.

  3. 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 as https://*.example.com matches one level of subdomain.

  4. 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.

  5. 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

  1. In the sidebar, click Agents. In the row of the personal-assistant agent, click the edit icon.

  2. From the Egress policies list at the end of the form, choose github-api.

  3. 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

  1. 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 admitted
    
  2. Check that the agent is ready.

    kubectl get agent personal-assistant -n kagent

    The READY column shows True.

What you built

An agent that can reach one external API, while every other host stays blocked. Along the way, you used these features:

FeatureWhat you didRead more
Egress policiesListed an origin that agents may reachEgress policies
Agent egress referencesAttached the policy to one agentEgress policies

Clean up

  1. Detach the policy from the agent. In the kagent UI, edit personal-assistant, clear github-api from the Egress policies list, and click Save agent. If you applied the YAML, reapply the agent without egressPolicyRefs.

  2. Delete the policy.

    kubectl delete egresspolicy github-api -n kagent

Next steps