import { useState } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { client } from '@/ui/api/client' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card' import { Input } from '@/ui/components/ui/input' import { Button } from '@/ui/components/ui/button' import { Loader2, Plus, X, Globe, Check, Trash2, ShieldAlert } from 'lucide-react' import { toast } from 'sonner' export function SandboxSettings({ teamId }: { teamId: string }) { const queryClient = useQueryClient() const [newDomain, setNewDomain] = useState('') const { data: sandbox, isLoading } = useQuery({ queryKey: ['teams', teamId, 'sandbox'], queryFn: async () => { const res = await client.api.teams[':teamId'].sandbox.$get({ param: { teamId }, }) if (!res.ok) throw new Error('Failed to fetch sandbox settings') return await res.json() }, }) const { mutate: updateSandbox, isPending: isUpdating } = useMutation({ mutationFn: async (params: { allowedDomains: string[]; pendingDomains: string[] }) => { const res = await client.api.teams[':teamId'].sandbox.$put({ param: { teamId }, json: params, }) if (!res.ok) throw new Error('Failed to update sandbox settings') return await res.json() }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'sandbox'] }) toast.success('Sandbox settings updated') }, onError: (err) => { toast.error(err instanceof Error ? err.message : 'Failed to update sandbox settings') }, }) const handleAddDomain = (e: React.FormEvent) => { e.preventDefault() if (!newDomain.trim()) return if (sandbox?.allowedDomains.includes(newDomain.trim())) { toast.error('Domain already exists') return } const updatedAllowed = [...(sandbox?.allowedDomains || []), newDomain.trim()] const updatedPending = sandbox?.pendingDomains || [] updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending }) setNewDomain('') } const handleRemoveDomain = (domain: string) => { const updatedAllowed = (sandbox?.allowedDomains || []).filter((d) => d !== domain) const updatedPending = sandbox?.pendingDomains || [] updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending }) } const handleApproveDomain = (domain: string) => { const updatedAllowed = [...(sandbox?.allowedDomains || []), domain] const updatedPending = (sandbox?.pendingDomains || []).filter((d) => d !== domain) updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending }) } const handleDeletePendingDomain = (domain: string) => { const updatedPending = (sandbox?.pendingDomains || []).filter((d) => d !== domain) updateSandbox({ allowedDomains: sandbox?.allowedDomains || [], pendingDomains: updatedPending }) } if (isLoading) { return (
) } return (
Network Sandbox
Configure allowed domains for the sandboxed agent. By default, only essential domains are allowed.
setNewDomain(e.target.value)} disabled={isUpdating} />

Allowed Domains

{sandbox?.allowedDomains.map((domain) => (
{domain}
))} {sandbox?.allowedDomains.length === 0 && (
No custom domains allowed
)}
{/* Pending Domains Section */}
Pending Domain Approvals
These domains were blocked during agent execution. You can approve them to allow future network requests, or delete them from this list.
{sandbox?.pendingDomains && sandbox.pendingDomains.length > 0 ? (
{sandbox.pendingDomains.map((domain) => (
{domain}
))}
) : (
No pending domains requiring approval
)}
Filesystem Restriction The agent is restricted to reading and writing only within the .pi and{' '} /tmp folders. These settings are currently hardcoded for security.
) }