How does the SANDBOX_ID property work ? can i use ...
# ask-ai
f
How does the SANDBOX_ID property work ? can i use that to have a single project with multiple agents but forcing a frontend to connect to a specific agent by Sandbox ID ?
t
Thanks for reaching out, Carlos. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
SANDBOX_ID
property is a handy way to authenticate and connect your frontend applications to LiveKit's sandbox environment, especially when you're working on development and testing. It makes getting tokens much easier since you don’t need to set up a custom backend token server. Now, while the
SANDBOX_ID
itself doesn’t directly link your frontend to a specific agent, you can definitely use it alongside the
agentName
parameter in your room configuration to connect to a particular agent. Here’s a little example to illustrate:
Copy code
const res = await fetch(url.toString(), {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Sandbox-Id': appConfig.sandboxId ?? '',
  },
  body: JSON.stringify({
    room_config: appConfig.agentName ? {
      agents: [{ agent_name: appConfig.agentName }]
    } : undefined,
  }),
});
With this setup, the LiveKit server can create a room that includes the agent you specified, so both your frontend and that agent can join the same room seamlessly. If you have any questions or need a bit more help, please don’t hesitate to reach out—I’m here to support you! Sources: README.md | Sources/LiveKit/Token/SandboxTokenSource.swift | README.md | Template System & Example Applications | livekit/livekit_composite | DeepWi...
f
How can i set multiple agents for multiple environments, e.g Dev A Dev B
t
I'm happy to guide you through setting up multiple agents for different environments like Dev A and Dev B. Here's a straightforward way to do this: 1. Create Separate Projects: Start by creating separate projects in LiveKit Cloud for each environment (Dev A, Dev B, etc.). This way, each project will have its own unique URL, API key, and secret, keeping everything nicely separated. 2. Environment-Specific Configuration: Use
.env
files tailored to each environment. For example, you can create
.env.devA
and
.env.devB
files with these variables:
Copy code
LIVEKIT_URL=your_devA_url
LIVEKIT_API_KEY=your_devA_api_key
LIVEKIT_API_SECRET=your_devA_api_secret
3. Agent Deployment: When deploying agents, use commands specific to the environment. For instance: ◦ For Python agents: run
python myagent.py dev
for development or
python myagent.py start
for production. ◦ For Node.js agents: run
pnpm run build && node agent.ts dev
for development or
pnpm run build && node agent.ts start
for production. 1. Agent Dispatch: You can specify which agent to connect to using the
room_config
parameter. For example:
Copy code
room_config: {
  agents: [{ agent_name: "DevA_Agent" }]
}
2. Namespace Isolation: To keep things even more organized, use namespaces in agent registration to separate agent pools. For example, in Python:
ac.Run(JobType, "namespace")
. If any of these steps feel unclear or if you'd like me to walk you through any part in more detail, please don’t hesitate to ask. I’m here to help! Sources: Voice Assistant Applications | livekit/livekit_composite | DeepWiki | test/agent_test.go | Workflows | LiveKit Docs | Deploying to custom environments | LiveKit Docs | README.md
f
Let me rephrase the question with the specific issue: Dev A is using Project A to connect to LiveKit in its Dev Machine If Dev B uses the same LiveKit Credentials it is possible that the agent that joins is the one from Agent A. Is there a way to let them have their own dev agents without having multiple projects ? Specially for billing purposes this is problematic
t
Great news! You can absolutely set up separate dev agents (like Dev A and Dev B) using the same LiveKit project credentials without the hassle of creating multiple projects. Here’s a friendly guide to help you through it: 1. Shared Project Credentials: Both agents simply share the same
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
environment variables. 2. Distinguish Agents via Agent Name: Use the
room_config
parameter to specify which agent you want to dispatch. For example:
Copy code
room_config: {
  agents: [{ agent_name: "DevA_Agent" }]
}
3. Assign Unique Agent Names: Make sure each agent script (like
dev_a.py
and
dev_b.py
) registers with its own unique name or namespace. This way, Dev A and Dev B are recognized as separate agents. 4. Run Agents Independently: You can run each agent on its own by using commands such as
python agent_a.py dev
and
python agent_b.py dev
to start them in development mode. 5. Optional Metadata: If you want, you can pass structured metadata (like
{"developer": "Dev A"}
) during dispatch to help differentiate agents in your logs and behavior. This setup helps keep things simple by avoiding multiple projects, while still giving each developer their own isolated agent environment. If anything feels unclear or if you’d like a hand with any step, just let me know—I’m here to help! Sources: Deploying to custom environments | LiveKit Docs | Voice Assistant Applications | livekit/livekit_composite | DeepWiki | README.md | Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | Agent dispatch | LiveKit Docs
f
So with this approach i could also have the QA and Prod agents right ? So Project A • Frontend from Dev Machine 1 connects to a agent named Agent Dev 1 • Frontend from Dev Machine 2 connects to a agent named Agent Dev 2 • Frontend from QA env connects to a agent named Agent QA • Frontend from Prod env connects to a agent named Agent Prod And they can run different code from each other despite being in the same LiveKit project ?
t
Absolutely! With this approach, you can easily have separate agents for Dev, QA, and Prod environments all within the same LiveKit project. Here’s a friendly breakdown of how it works: • Frontend from Dev Machine 1 connects to Agent Dev 1: Just use
agent_name="Agent Dev 1"
in the room configuration to make sure this specific agent is dispatched. • Frontend from Dev Machine 2 connects to Agent Dev 2: Similarly, use
agent_name="Agent Dev 2"
to dispatch this agent smoothly. • Frontend from QA connects to Agent QA: Configure the room with
agent_name="Agent QA"
to route it correctly. • Frontend from Prod connects to Agent Prod: Use
agent_name="Agent Prod"
to handle production-specific logic confidently. Each agent can run its own code since they’re identified by their
agent_name
or namespace. This setup helps you keep your logic and behavior nicely separated for each environment, while still using the same LiveKit project credentials. If you’d like, I’m here to help with any more details or guide you through setting this up step-by-step! Sources: Deploying to custom environments | LiveKit Docs | examples/agent_dispatch.py | Agent dispatch | LiveKit Docs | test/agent_test.go
f
So, that is a config on both sides right ? (Frontend and Agent code) the frontend should request that specific room, and the agent.py must run the agent in that room ?
t
Absolutely, this setup does need some configuration on both the frontend and the agent side to work smoothly: • Frontend/Token Server: Here, the frontend (or token server) should request a room with a specific agent by including the
agent_name
in the
room_config
. This step helps the LiveKit server know exactly which agent to connect you with. • Agent-Side: On the agent’s end (like in
agent.py
), it’s important that the agent is running and registered using the same
agent_name
. This way, it can listen for dispatch events and join the room when it’s called. Both sides really need to be on the same page with key details like the room name, agent name, and environment variables (such as
LIVEKIT_API_KEY
and
LIVEKIT_API_SECRET
). If these don’t match up, the agent might not be dispatched properly. Please feel free to reach out if you’d like a hand setting up either the frontend or the agent configuration—I’m here to help! Sources: OpenAI and LiveKit partner to turn Advanced Voice into an API | README.md | Voice Assistant Applications | livekit/livekit_composite | DeepWiki | complex-agents/ivr-agent/README.md | README.md
f
So if my frontend doesnt generate a token, that is done at the app backend, does it need to know the agent name ? or that is just needed when generating the token and the Frontend doesnt need to know
t
Just to clarify, the agent name is only needed when the backend is generating the token. Once that’s done and the agent name is embedded in the token through the
RoomConfiguration
, the LiveKit server takes care of dispatching the agent automatically. After the token is generated, the frontend doesn’t need to worry about the agent name anymore. It simply uses the token to connect to the room, and the LiveKit server makes sure the right agent is assigned based on what’s in the token. If you have any questions or want me to walk you through the token generation process, just let me know—I’m here to help! Sources: src/pages/api/token.ts | app/api/connection-details/route.ts | Voice Assistant Applications | livekit/livekit_composite | DeepWiki | Sources/LiveKit/Token/EndpointTokenSource.swift