Skip to content

Internet access

Sandboxes can access the internet by default. For example, a command inside a sandbox can call an HTTPS endpoint:

mjs
import { Sandbox } from "@abox-dev/sdk";

const sandbox = await Sandbox.create();

try {
  const result = await sandbox.commands.run(
    "curl -fsS -o /dev/null -w '%{http_code}\\n' https://example.com/",
  );
  console.log(result.stdout);
} finally {
  await sandbox.kill();
}

Disable internet access

Set allowInternetAccess in JavaScript or allow_internet_access in Python to false. Commands and files continue to work, but the sandbox cannot open outbound connections.

mjs
import { Sandbox } from "@abox-dev/sdk";

const sandbox = await Sandbox.create({ allowInternetAccess: false });

try {
  const result = await sandbox.commands.run("printf 'sandbox is running\\n'");
  console.log(result.stdout);
} finally {
  await sandbox.kill();
}

Allow selected destinations

Use allowOut and denyOut to restrict egress. The following configuration allows HTTPS requests to example.com and denies every other destination:

mjs
import { Sandbox } from "@abox-dev/sdk";

const sandbox = await Sandbox.create({
  network: {
    allowOut: ["example.com"],
    denyOut: ({ allTraffic }) => [allTraffic],
  },
});

try {
  const result = await sandbox.commands.run(
    "curl -fsS -o /dev/null -w '%{http_code}\\n' https://example.com/",
  );
  console.log(result.stdout);
} finally {
  await sandbox.kill();
}

Allow-list entries can be IP addresses, CIDR blocks, exact domain names, or domain names beginning with *.. Domain matching works for HTTP on port 80 and TLS on port 443. Use only IP addresses and CIDR blocks for other ports.

Domains are not valid in denyOut or deny_out. An allow rule takes priority when the same address is also covered by a deny rule.

Update a running sandbox

Network settings can be replaced without restarting the sandbox:

mjs
import { Sandbox } from "@abox-dev/sdk";

const sandbox = await Sandbox.create();

try {
  await sandbox.updateNetwork({ allowInternetAccess: false });
  const result = await sandbox.commands.run("printf 'network updated\\n'");
  console.log(result.stdout);
} finally {
  await sandbox.kill();
}

updateNetwork and update_network replace the complete egress configuration. Fields omitted from an update are cleared instead of being merged with the previous settings.