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 } 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 (allowedDomains: string[]) => { const res = await client.api.teams[':teamId'].sandbox.$put({ param: { teamId }, json: { allowedDomains }, }) 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 updated = [...(sandbox?.allowedDomains || []), newDomain.trim()] updateSandbox(updated) setNewDomain('') } const handleRemoveDomain = (domain: string) => { const updated = (sandbox?.allowedDomains || []).filter((d) => d !== domain) updateSandbox(updated) } 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
)}
Filesystem Restriction The agent is restricted to reading and writing only within the .pi and{' '} /tmp folders. These settings are currently hardcoded for security.
) }