open, interoperable sandbox platform for agents and humans 📦 ✨
pocketenv.io
claude-code
atproto
sandbox
openclaw
agent
1import { client } from ".";
2import type { Port } from "../types/port";
3import type { Provider } from "../types/providers";
4import type { Sandbox } from "../types/sandbox";
5
6export const createSandbox = ({
7 base,
8 provider,
9 challenge,
10 repo,
11}: {
12 base: string;
13 provider: Provider;
14 challenge: string | null;
15 repo?: string;
16}) =>
17 client.post<Sandbox | undefined>(
18 "/xrpc/io.pocketenv.sandbox.createSandbox",
19 {
20 base,
21 provider,
22 repo,
23 },
24 {
25 headers: {
26 Authorization: `Bearer ${localStorage.getItem("token")}`,
27 "X-Challenge": challenge ?? "",
28 },
29 },
30 );
31
32export const claimSandbox = ({ id }: { id: string }) =>
33 client.post<{ sandbox: Sandbox | undefined }>(
34 "/xrpc/io.pocketenv.sandbox.claimSandbox",
35 undefined,
36 {
37 params: {
38 id,
39 },
40 headers: {
41 Authorization: `Bearer ${localStorage.getItem("token")}`,
42 },
43 },
44 );
45
46export const getSandbox = (id: string) =>
47 client.get<{ sandbox: Sandbox | undefined }>(
48 "/xrpc/io.pocketenv.sandbox.getSandbox",
49 {
50 params: {
51 id,
52 },
53 headers: {
54 Authorization: `Bearer ${localStorage.getItem("token")}`,
55 },
56 },
57 );
58
59export const getSandboxes = (offset?: number, limit?: number) =>
60 client.get<{ sandboxes: Sandbox[]; total: number }>(
61 `/xrpc/io.pocketenv.sandbox.getSandboxes?offset=${offset ?? 0}&limit=${limit ?? 30}`,
62 );
63
64export const getActorSandboxes = (
65 did: string,
66 offset?: number,
67 limit?: number,
68) =>
69 client.get<{ sandboxes: Sandbox[]; total: number }>(
70 `/xrpc/io.pocketenv.actor.getActorSandboxes?did=${did}&offset=${offset ?? 0}&limit=${limit ?? 30}`,
71 );
72
73export const stopSandbox = (id: string) =>
74 client.post("/xrpc/io.pocketenv.sandbox.stopSandbox", undefined, {
75 params: {
76 id,
77 },
78 headers: {
79 Authorization: `Bearer ${localStorage.getItem("token")}`,
80 },
81 });
82
83export const deleteSandbox = (id: string) =>
84 client.post("/xrpc/io.pocketenv.sandbox.deleteSandbox", undefined, {
85 params: {
86 id,
87 },
88 headers: {
89 Authorization: `Bearer ${localStorage.getItem("token")}`,
90 },
91 });
92
93export const startSandbox = (id: string) =>
94 client.post(
95 "/xrpc/io.pocketenv.sandbox.startSandbox",
96 {},
97 {
98 params: {
99 id,
100 },
101 headers: {
102 Authorization: `Bearer ${localStorage.getItem("token")}`,
103 },
104 },
105 );
106
107export const putPreferences = () =>
108 client.post(
109 `/xrpc/io.pocketenv.sandbox.putPreferences`,
110 {},
111 {
112 headers: {
113 Authorization: `Bearer ${localStorage.getItem("token")}`,
114 },
115 },
116 );
117
118export const getPreferences = () =>
119 client.get(`/xrpc/io.pocketenv.sandbox.getPreferences`, {
120 headers: {
121 Authorization: `Bearer ${localStorage.getItem("token")}`,
122 },
123 });
124
125export const exposePort = (
126 id: string,
127 {
128 port,
129 description,
130 }: {
131 port: number;
132 description?: string;
133 },
134) =>
135 client.post(
136 `/xrpc/io.pocketenv.sandbox.exposePort`,
137 { port, description },
138 {
139 params: {
140 id,
141 },
142 headers: {
143 Authorization: `Bearer ${localStorage.getItem("token")}`,
144 },
145 },
146 );
147
148export const unexposePort = (id: string, port: number) =>
149 client.post(
150 `/xrpc/io.pocketenv.sandbox.unexposePort`,
151 { port },
152 {
153 params: {
154 id,
155 },
156 headers: {
157 Authorization: `Bearer ${localStorage.getItem("token")}`,
158 },
159 },
160 );
161
162export const getExposedPorts = (id: string) =>
163 client.get<{ ports: Port[] }>(`/xrpc/io.pocketenv.sandbox.getExposedPorts`, {
164 params: {
165 id,
166 },
167 headers: {
168 Authorization: `Bearer ${localStorage.getItem("token")}`,
169 },
170 });
171
172export const exposeVscode = (id: string) =>
173 client.post<{ previewUrl?: string }>(
174 `/xrpc/io.pocketenv.sandbox.exposeVscode`,
175 undefined,
176 {
177 params: {
178 id,
179 },
180 headers: {
181 Authorization: `Bearer ${localStorage.getItem("token")}`,
182 },
183 },
184 );