mirror of
https://github.com/yashshah9/agentbox.git
synced 2026-11-19 02:16:20 +00:00
Support AGENTBOX_EGRESS_ALLOWLIST and per-request egress_allowlist. Empty list keeps deny-all (Docker --network=none / Linux netns); a non-empty list applies a soft Python/Node userspace filter and returns the effective hosts on the run response.
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
/**
|
|
* Minimal TypeScript client for agentbox.
|
|
* Usage: const box = new AgentboxClient("http://localhost:8080")
|
|
*/
|
|
export type LimitsApplied = {
|
|
timeout_seconds: number;
|
|
memory_mb: number | null;
|
|
};
|
|
|
|
export type RunResult = {
|
|
stdout: string;
|
|
stderr: string;
|
|
exit_code: number;
|
|
duration_ms: number;
|
|
language: string;
|
|
backend: string;
|
|
snapshot_id?: string | null;
|
|
limits_applied: LimitsApplied;
|
|
oom_killed: boolean;
|
|
network_isolated: boolean;
|
|
egress_allowlist?: string[];
|
|
};
|
|
|
|
export class AgentboxClient {
|
|
constructor(private readonly baseUrl: string = "http://localhost:8080") {}
|
|
|
|
async health(): Promise<{ status: string; version: string; backend: string }> {
|
|
const res = await fetch(`${this.baseUrl}/health`);
|
|
if (!res.ok) throw new Error(`health failed: ${res.status}`);
|
|
return res.json();
|
|
}
|
|
|
|
async run(
|
|
code: string,
|
|
language = "python",
|
|
timeoutSeconds?: number,
|
|
memoryMb?: number,
|
|
egressAllowlist?: string[],
|
|
): Promise<RunResult> {
|
|
const body: Record<string, unknown> = { code, language };
|
|
const limits: Record<string, number> = {};
|
|
if (timeoutSeconds) limits.timeout_seconds = timeoutSeconds;
|
|
if (memoryMb != null) limits.memory_mb = memoryMb;
|
|
if (Object.keys(limits).length) body.limits = limits;
|
|
if (egressAllowlist) body.egress_allowlist = egressAllowlist;
|
|
const res = await fetch(`${this.baseUrl}/v1/run`, {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify(body),
|
|
});
|
|
if (!res.ok) throw new Error(`run failed: ${res.status} ${await res.text()}`);
|
|
return res.json();
|
|
}
|
|
}
|